Python 使用QThread的PyQt分段错误
我想在用Python编写的PyQt的项目中使用QThreads,但当我运行这段代码时,我收到一个错误,它没有告诉我什么:Python 使用QThread的PyQt分段错误,python,segmentation-fault,pyqt,qthread,Python,Segmentation Fault,Pyqt,Qthread,我想在用Python编写的PyQt的项目中使用QThreads,但当我运行这段代码时,我收到一个错误,它没有告诉我什么: segmentation fault (core dumped) python file.py 我不知道这是什么意思,也不知道代码有什么问题。 这是我的密码: import sys from PyQt4 import QtCore, QtGui import time from PyQt4.QtCore import SIGNAL, QObject, QTimer imp
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_())
导入系统
从PyQt4导入QtCore、QtGui
导入时间
来自PyQt4.QtCore导入信号,QObject,QTimer
将libtorrent作为lt导入
尝试:
_fromUtf8=QtCore.QString.fromUtf8
除属性错误外:
来自UTF8的def_:
返回s
尝试:
_编码=QtGui.QApplication.UnicodeUTF8
定义翻译(上下文、文本、消歧):
返回QtGui.QApplication.translate(上下文、文本、消歧、_编码)
除属性错误外:
定义翻译(上下文、文本、消歧):
返回QtGui.QApplication.translate(上下文、文本、消歧)
类Ui_表单(对象):
def setupUi(自我,表格):
#一些代码。。。
def重新传输(自身,表格):
#一些代码。。。
类MyForm(QtGui.QMainWindow):
def uuu init uuu(self,parent=None):
QtGui.QWidget.\uuuuu init\uuuuuu(self,parent)
self.ui=ui_Form()
self.ui.setupUi(self)
类可运行(QtCore.QRunnable):
def运行(自):
计数=0
app=QtCore.QCoreApplication.instance()
当计数小于5时:
打印“增加”
时间。睡眠(1)
计数+=1
app.quit()
如果名称=“\uuuuu main\uuuuuuuu”:
app=QtGui.QApplication(sys.argv)
apps=QtCore.QCoreApplication(sys.argv)
myapp=MyForm()
myapp.show()
runnable=runnable()
QtCore.QThreadPool.globalInstance().start(可运行)
sys.exit(app.exec_())
不允许创建多个应用程序实例。注释
apps=QtCore.QCoreApplication(sys.argv)
out,它可以正常工作。Ubuntu 13.04和最新更新您可以尝试的一件事是重新安装PyQt。另一件事是确保所有模块都是从未损坏的文件导入的。您可以通过在另一台机器上运行代码来检查这一点,例如在虚拟机上运行代码。