Problem with signal system
-
Hello,
I will try to explain my problem (about order of receive signal):
I've two different object instanciate (O1, O2) and two qml files (Q1, Q2).
In one qml file Q1, I made a connection between signal from O1 and slot from O2.
In O1 I have a Q_PROPERTY (read write notify).
In the setter of the Q_PROPERTY I have an emit of the previous signal.
During the execution I regulary emit the signal (out of the setter), and when I press a button in Q2, it call the setter of the O1's Q_PROPERTY and so emit the signal and stop the other emission.The problem is that the slot in O2 receive signals in a bad order : signal send in the setter is immediatly receive, before some signal which are emit before.
Is it clear :/ ?
Edit: Same if I use a Q_INVOKABLE function instead of setter.
Thank
-
Hi,
Not really clear, can you show a code sample ?
-
Object1:
@Q_PROPERTY property READ WRITE NOTIFY
while(update) {
emit signalToObject2();
}
propertySet() {
update = false;
emit signalToObject2();
}@Object2:
@slotReceiveSignalFromObject1() {
...
}@QML1:
@object1.signalToObject2.connect(Object2.slotReceiveSignalFromObject1);@QML2:
@button {
onClicked: object1.property = ...;
}@Result is when I click, I receive immediatly the signal send in propertySet() and after I receive signal which were pending (send in while, before the set). Like if in the set, signals are priority.
You see ? Thank to try to understand me ^^'
-
Sending signals from a while loop like that is bad design, why are you doing it ?
-
Sorry it's just to describe the problem.. I'm working on leap motion, the while in my example correspond to a listener connected to the leap motion frames. Like:
@void object1::onFrameReceive()
{
if (drawHand)
emit signalToObject2()
}@ -
Got any thread running ?
-
Can we get a working example? The pseudocode posted leaves large gaps that could contain all sorts of hypothetical problems. We can spend all day guessing about situations that don't apply to the real problem.
-
I can't give you a working example...
I feel that sending a signal in a classic function call is not the same as sending a signal in a setter call throught the Q_PROPERTY system like if there is a priority or an immediate call to the function (bypassing the queue).
Do you thing it's possible ?I'm starting with Qt sorry..
-
Lacking a working example, or valid C++ and QML, my suggestion is to read the documentation on signals and slots, and the property system.
Depending on the connection, delivery of a signal to a slot may occur via a direct function call, or the event loop of the receiver.
-
The connection is made under QML, so I can't choose connection mode. I think this is automatic connection ? Maybe one signal use queued connection and the other use direct ?