[英]PyQt segmentation fault with QThread
我想在用PyQt用Python編寫的項目中使用QThreads,但是當我運行此代碼時,我收到一條錯誤消息,它什么也沒說:
segmentation fault (core dumped) python file.py
我不知道這意味着什么,代碼有什么問題。 那是我的代碼:
import sys
from PyQt4 import QtCore, QtGui
import time
from PyQt4.QtCore import SIGNAL, QObject, QTimer
import libtorrent as lt
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_Form(object):
def setupUi(self, Form):
#some code...
def retranslateUi(self, Form):
#some code...
class MyForm(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Form()
self.ui.setupUi(self)
class Runnable(QtCore.QRunnable):
def run(self):
count = 0
app = QtCore.QCoreApplication.instance()
while count < 5:
print "Increasing"
time.sleep(1)
count += 1
app.quit()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
apps = QtCore.QCoreApplication(sys.argv)
myapp = MyForm()
myapp.show()
runnable = Runnable()
QtCore.QThreadPool.globalInstance().start(runnable)
sys.exit(app.exec_())
您不允許創建multipe應用程序實例。 注釋apps = QtCore.QCoreApplication(sys.argv)
,它可以工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.