search

Home  >  Q&A  >  body text

qt - [Python] 段错误-用QWebView

编一个QWebView的小段测试一下,结果报段错误,这个要怎么调?
怀疑和QWebView以及QWebKit组件有关,看了外网资料说是Debian的BUG,所以我的linuxmint里安装仓库里的qt designer都没有QWebView这个组件的。

代码如下:

# coding: utf-8
from PySide.QtCore import *
from PySide.QtGui import *
import PySide.QtWebKit as qw

app = QApplication([])
win = qw.QWebView()
 
img = open('1.png', 'rb').read()
win.setContent(img, 'image/png')
 
win.setWindowFlags(Qt.SplashScreen)
win.show()
QTimer.singleShot(10000,app.quit)
app.exec_()

执行效果如下图:

经提示,胡乱修改了一下代码,可以执行了,发现原来是因为png格式造成的段错误,改成jpg就可以打开。

# coding: utf-8
from PySide.QtCore import *
from PySide.QtGui import *
import PySide.QtWebKit as qw

print '1'
app = QApplication([])
print '2'
win = qw.QWebView()
print '3' 
file=open('002.jpg','rb')
img = file.read()
print '4'
win.setContent(img, 'image/jpg')
print '5' 
win.setWindowFlags(Qt.SplashScreen)
print '6'
win.show()
QTimer.singleShot(10000,app.quit)
app.exec_()


阿神阿神2889 days ago306

reply all(1)I'll reply

  • 黄舟

    黄舟2017-04-17 17:37:33

    1) Print in the middle of each statement to see where the segmentation error is.
    2) Try another distribution, such as Ubuntu. 3) Try changing 1.png to an absolute path.

    reply
    0
  • Cancelreply