jpn:
My comment about the design in the code you posted is not directly connected to the problem you raised with the cross thread communication.
And since its a design issue, it really has nothing to do with the size of the code, but on it functionality.
Its a bad practice to mix view and functionality.
It is good practise to use encapsulation when programming C++ (OOP).
I offered it as a constructive comment, its ok if you don't agree with it.
And, it *could* be that with a correct design your inter thread communication problem would be solved or easer to handle.
While I don't mind if you agree with my above comment I do mind the following since its missleading others:
This is not true.You cannot emit signals or post events ACROSS THREAD to a QThread descendant object.
From the docs:
And :It is important to keep in mind that the event loop may be delivering events to your QObject subclass while you are accessing the object from another thread.
No - when you send signal across threads its execution depends on what kind of a connection you made:When using signals and slots, the slot will be executed in the main thread and when posting event's, the event gets posted in the main event loop.
If its a direct connetion the slot will be executed in the thread in which the signal was emmited, that does not have to be the main thread.
If the connection you made is a qued connection then the slot will be executed in the thread in which the object that has the slot lives in, again, does not have to be the main thread.
I would advise you to read the chapter about threading in the Qt4 docs.





Reply With Quote


Bookmarks