首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >QThread的PyQt分段故障

QThread的PyQt分段故障
EN

Stack Overflow用户
提问于 2013-05-26 23:27:19
回答 1查看 1.2K关注 0票数 0

我希望在使用PyQt的Python语言编写的项目中使用QThreads,但是当我运行这段代码时,我收到一个错误,它没有告诉我什么:

代码语言:javascript
运行
复制
segmentation fault (core dumped)  python file.py

我不知道这是什么意思,也不知道代码有什么问题。这是我的代码:

代码语言:javascript
运行
复制
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_())
EN

Stack Overflow用户

发布于 2013-05-27 00:45:12

不允许创建多个应用实例。注释掉apps = QtCore.QCoreApplication(sys.argv),它就可以工作了。

票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16760723

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档