Sunday, July 03, 2011

Cross thread signal delivery fixed!

At work we've been chasing for a long time a problem in which thread T1 emitted signal S1 and then signal S2 connected to an object in thread T2 but they were received in that object in the reverse order, that is, S2 first and S1 later.

First we though it was our fault since the code in those classes is not as clean as it should be, but after days we could not find anything specially wrong in our code so started looking down to Qt.

Just after one day I was able to locate a problem in QObject::moveToThread that did not keep the entries in QPostEventList properly sorted and was able to produce a quick patch to fix our issue. Unfortunately it has taken around one month for that patch to hit upstream (no idea if it stalled in my company, digia or nokia) and the bug being fixed by Olivier (with a patch better than mine).

Bottom line: If you can not find the bug in your code it's maybe because it's not there :D


sebsauer said...

Good it was fixed and bad your patch was lost. Why no merge-request?

Albert Astals Cid said...

As said Olivier patch is better than mine so no grief for my lost patch. About no merge-request, my boss preferred to go the Digia way since they are the ones we have business with.

sebsauer said...

I see, makes sense and thanks for sharing :)

STiAT said...

Wow, thanks! I was hit by this lately and was searching like crazy for the problem.

I gave up in the end and worked it back to one thread, what's not a nice solution.

Thanks for sharing that's, this is great news!