PySide passing signals from QThread to a slot in another QThread

后端 未结 1 1086
难免孤独
难免孤独 2021-01-15 01:08

I solved my issue by moving the mySubQThread run() into the myQThread run()

That said, I still

1条回答
  •  隐瞒了意图╮
    2021-01-15 01:20

    The problem is because you have overridden QThread.run(). The run method by default contains an implementation that handles signal processing.

    If you want to use signals/slots correctly you should subclass QObject, put your code in a method in there, and use moveToThread() to move the QObject to a base instance of QThread that you instantiate. You can then run your code by connecting your method to the QThread.started signal and then calling thread.start()

    You can then repeat the creation of the child thread in a similar way, by putting that code in the method of the QObject previously created and launched in the thread. Signals and slots you connect there will be made between the thread and it's child thread correctly.

    This is a good example of proper communication between the main thread and a QThread, but you could easily extend it to between QThreads. Just modify the MyWorker.firstWork() method to launch a new QThread like is already done in the setupThread method.

    0 讨论(0)
提交回复
热议问题