0

I am developping a Python GUI application with pyqt. I need to keep the python console responsive while using the GUI, so my GUI is started in a another thread, in this way :

class AppThread(Thread):

    def __init__(self):
        Thread.__init__(self)

    def run(self):

        from PyQt5 import QtWidgets

        app = QtWidgets.QApplication.instance()
        if app is None:
           app = QtWidgets.QApplication([])

        from mywindow import MyWindow # The code of the window is in another python script
        gui = MyWindow()
        gui.show()
        app.exec_()

if __name__ == '__main__' :
    myapp = AppThread()

The GUI is working well, but when I close it, I get the following error :

QObject::~QObject: Timers cannot be stopped from another thread

Of course, I don't get this error if I run directly the code :

from PyQt5 import QtWidgets

app = QtWidgets.QApplication.instance()
if app is None:
    app = QtWidgets.QApplication([])

from mywindow import MyWindow # The code of the window is in another python script
gui = MyWindow()
gui.show()
app.exec_()

My question is then how to get rid of this error when instantiating a gui in a thread that is not the main one ?

qcha
  • 523
  • 1
  • 5
  • 19

0 Answers0