0

I would like to use QThreads in my project written in Python with PyQt, but when I run this code, I recieve an error, which says me nothing:

segmentation fault (core dumped)  python file.py

I don't know what that means and what is wrong with the code. That's my code:

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_())
2
  • Ubuntu 13.04 with latest updates Commented May 26, 2013 at 15:35
  • One thing that you can try is to reinstall PyQt. Another thing would be to make sure all you modules are imported from non-corrupt files. You can check this by running your code on another machine such as one on a virtual box. Commented May 26, 2013 at 15:47

1 Answer 1

0

You're not allowed to create multipe application instances. Comment apps = QtCore.QCoreApplication(sys.argv) out and it works.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.