我尝试使用QWebEnginePage重新启动pyqt5应用程序。但得到了段错误。这是代码示例:
import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import qApp
#from PyQt5.QtWebEngineWidgets import QWebEnginePage
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWebEngineWidgets import QWebEngineView
class MainWindow(QMainWindow):
EXIT_CODE_REBOOT = -123
def __init__(self,parent=None):
QMainWindow.__init__(self, parent)
self.timer = QTimer()
self.timer.timeout.connect(self.restart)
self.timer.start(3 * 1000)
self.qwe = QWebEngineView()
#self.qp = QWebEnginePage() # uncomment this will cause Segmentation fault (core dumped)
def restart(self):
print('restart')
qApp.exit(MainWindow.EXIT_CODE_REBOOT)
if __name__=="__main__":
currentExitCode = MainWindow.EXIT_CODE_REBOOT
while currentExitCode == MainWindow.EXIT_CODE_REBOOT:
print('next..')
a = QApplication(sys.argv)
w = MainWindow()
w.show()
currentExitCode = a.exec_()
a = None
有了这个评论 - 它运作正常。但是,如果删除评论' Segmentation fault(core dumped)'出现。
你能给我一个建议吗?
转载于PyQt 5.9.3和Ubuntu 14.04
答案 0 :(得分:0)
当我使用anaconda PyQt5时出现相同的错误
我通过
安装了PyQt5conda install -c anaconda pyqt
错误结果:
>>> from PyQt5 import *
>>> from PyQt5.QtGui import *
Segmentation fault (core dumped)
解决方法:
pip install PyQt5
结果:
>>> from PyQt5 import *
>>> from PyQt5.QtGui import *
>>>
希望它有效!