Callback and Signal-Slot?
I have question about using both callback and Signal/Slot in a Qt application.
I have a external library that calling my qt application via callback. In the Qt application as normal I am using Signal and Slot. So in order to not have any problem what is the best way to handle both callback and Signal ?
Right now, I am handling in following manner,
1 ) Registering my callback method.
2 ) when my callback method invoked by library, I generate a signal and return from my callback method.
3 ) since signal is connected to a slot, it invoke it.
So far this method is working. But I want see if you have better approach that can handle this station.
I also want to know if there is a side affect of the approach I am using right now?
That's pretty much the standard way to write wrappers for non-Qt mechanisms.
The only comment I have here is that the order you presented is not quite right. For single threaded programs the default connection is a direct one, meaning that the actual emit is a blocking function calling all the connected slots, so the order is actually:
- Registering my callback method.
- when my callback method is invoked by library, I generate a signal
- since signal is connected to a slot, it invoke it.
- return from my callback method.
So that's something to keep in mind, usually in a context of order of destruction of things.
Actually, I am doing in the same order you wrote. :)
I will keep this topic, open so see others opinion.