Signal behaviour when object goes out of scope.
-
I am running a single-threaded application on 2 monitors, these monitors are touch monitors and they are running the same instance of the application.
Question is what will happen when somebody performs different operations on these 2 monitors at the same time.
Let me paint a scenario
There is a pop up on both the monitors with options Save, Don't Save, Cancel for some data.
Now somehow users manage to fire Save and Don't Save signal at the same time.Suppose Save signal calls the SLOT which saves the data and jumps to the next screen i.e. its object goes out of scope.
Now in the queue, we have Don't Save Signal which has some other SLOT to call but its object is already out of scope.
Main issue is here what will happen/ how the application is going to behave?? -
Hi, welcome to the forum.
@Shivendra-Pratap-Singh said in Signal behaviour when object goes out of scope.:
Now somehow users manage to fire Save and Don't Save signal at the same time.
First of all, if the app is single threaded, there's no such thing as "at the same time". Those calls will be serialized no matter what.
Without additional flags a connection on a single thread will call the slot immediately, so basically it's like a function call (with additional minor overhead). When QObject is deleted all connections to it are severed.So summing those factors in, if a slot connected to first signal deletes the object, by the time the second signal is fired the object is already gone and the signal is no longer connected to it. If it was the only connection to that signal emitting it will do nothing.
-
Hi, @Chris-Kawa Thanks for your quick reply.