Unsolved How does a signal know that slot has succesfully executed? Does signals and slots or connect() return any value?
-
I am a Qt noob. I would like to know whether a slot returns any value such that we can cross check or verify? Please also do let me know about some good Qt debugging tools and methods to learn more about Qt.
-
using qDebug() << "Your message"; inside your slot function?
-
Hi,
connect will return true or false based on a successful connection. However if you use the new Qt 5 syntax, any error in the connect statement will result in a build failure.
If you would like to have a slot return a value then I'd recommend using the Q_INVOKABLE and use QMetaObject::invokeMethod. In the end that will use the same mechanics as calling a slot but with the benefit that your code will be way clearer to understand. Also, developers that will be using your code later (yourself included) will thank you for the clear separation between slots and invokable methods.
Slots usually don't have return type, because that would be pretty hazardous in a threaded environment even though you have the possibility to use Qt::BlockingQueuedConnection. When starting to use thread you usually would like to avoid blocking the calling thread. In such an environment, you would rather start processing something in that other thread and at the end signal that the processing is done so the original calling thread (or another one) grabs the result either using a signal parameter or some getter function.
If you would like to learn more about Qt's internal then you should read KDAB's and Woboq's blogs about Qt as well as dive into the source code.