Reputation: 71
I have two classes, Class1, Class2 (Singleton), both use QT signals & slots. Each class contain instance of separate class Message: Msg1, Msg2 respectively
Class1: Signal-X from Msg1 is connected to Class1 slotX
Class2: Signal-X from Msg2 is connected to Class2 slotY.
When Class1 is instantiated, the constructor causes two messages being sent to Message Class, which will then cause Signal-X emitted by Message Class. Two messages means Signal emitted twice (with different parameter data). I have used Qt:AutoConnection during the signal and slot connection in both Class1, Class2.
Normally everything work normally as expected. But Some times I notice, Class1::SlotX() is not getting fired twice, where as Class2::SlotY() is fired twice!! The signal source is same in both cases!!!
Is it possible that when Class1 Event loops is busy, 2nd Signal-X overwrite the 1st Signal-X before Class1::SlotX() is used? For Singleton class Class2, there is no problem. The Class2::SlotY() is fired twice always.
Is the QT signal & slot connection immediate after Connect()? Or does it take time after which only signal and slot are connected?
Can some one please help... Thanks in advance
Upvotes: 3
Views: 168
Reputation: 2167
Here is an attempt to answer to your question 2.
Depending if your Class1 Class2 and Message classes are or not in the same thread, Qt::AutoConnection will result in different behaviour.
If both are on the same thread, it results in a direct connection, so the slot is called directly, as a callback, without invoking the event loop.
If not on the same thread, it is called indirectly through the event loop, so as a matter of fact you have no guarantee when the receiver's slot is executed.
For q1, as stated by Jeremy Friesner, code sample is needed
Upvotes: 0