首页 > [Python] 段错误-用QWebView

[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_()



1) 每个语句中间print下,看看具体是哪个地方段错误了
2) 换个发行版比如Ubuntu试试
3)1.png改成绝对路径试试

【热门文章】
【热门文章】