qt - [Python] 段错误-用QWebView
阿神
阿神 2017-04-17 17:35:33
0
1
299

编一个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_()


阿神
阿神

闭关修行中......

répondre à tous(1)
黄舟

1) Imprimez au milieu de chaque instruction pour voir où se trouve l'erreur de segmentation
2) Essayez une autre distribution telle qu'Ubuntu
3) 1. Essayez de changer le .png en un chemin absolu

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal