Qt signals slots threads example

broken image
broken image
broken image
broken image

The Qthread doc and example should really be updated if they still show inheritance of QThread, many green developer fall into the pit every time and I can understand if the doc still do this.įrom: Interest On Behalf Of Alexander Dyagilev You can see this article that explain the problem by inheriting the QThread: Since the Qthread belong to the thread creator and not the created thread you will have the wrong current thread for the current QObject that inherit QThread. Note: inheriting QThread is wrong practice and should probably never be done. You will have many problems the way you describe it, the fact that the thread B is launching the signal of Object that belong on Thread A, the automatic connection will check the ownership of the object emiting the signal to queue or not the signal and this will be wrong since the related thread is not the current thread. You should move the Object to the other thread or use a signals / slots to communicate between thread. The fact that QObject belong to Thread A and a method is used into Thread B should raise a flag, each QObject belong to a QThread and they should be used by that QThread only.

broken image