Solved Signals and slots without a slot
-
Hi,
@J-Hilk , @jsulm , @dheerendraI had a query regarding signals and slots.
If a signal is emitted from C++ but there is no slot defined to receive the signal in qml, what happens to the signal emitted, will it still go through the main thread, and when there is no slot to receive it, what happens to the signal that is emitted? -
@Anita said in Signals and slots without a slot:
what happens to the signal emitted, will it still go through the main thread
Signals do not "go through" any threads.
When a signal is emitted, Qt checks to see if any slots are connected. If there is >=1 slot connected, Qt will run those slots.
- If the connection type is Qt::AutoConnection or Qt::QueuedConnection (Recommended), then the slot will run in the slot's thread.
- If the connection type is Qt::DirectConnection (NOT recommended), then the slot will run in the thread that emitted the signal.
and when there is no slot to receive it, what happens to the signal that is emitted?
Nothing special happens.
As I described above, the signal emission just causes Qt to check for slots. If there are no slots connected, then the slot-check finishes very quickly.
-
Thank you for the response.