찾다

 >  Q&A  >  본문

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일 전308

모든 응답(1)나는 대답할 것이다

  • 黄舟

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

    1) 각 명령문 중간에 인쇄하여 분할 오류가 있는 위치를 확인하세요
    2) Ubuntu와 같은 다른 배포판을 사용해 보세요
    3) 1. .png를 절대 경로로 변경해 보세요

    회신하다
    0
  • 취소회신하다