Signals and slots are primarily used for communication between components, similar to the delegates in. NET and Java.
The signal is associated with the slot using the Qobject::connect method, and then the initiator of the signal signals that the slot function in the recipient executes.
such as connect(this,SIGNAL(Start()),worker,SLOT(Start() )) , associate the start signal in the current class to the start function of the Worker object, when we call emit this-> When start () is signaled, the slot function receives the signal.
The Connect function also has a fifth parameter, which determines when the signal is passed to the slot, which is mentioned here, but I am currently using the default value.
Qt::autoconnection, the default value is automatically connected, when the signal initiator and the slot function performer in the same thread, will use QT::D irectconnection, conversely, use qt::queuedconnection.
Qt::D irectconnection, directly connected, signal one the initiation slot function executes immediately, the signal initiator and the performer are on the same thread.
Qt::queuedconnection, queue, signal initiator and performer are not the same thread, when the signal is initiated, the slot function waits for dispatch.
Qt::blockingqueuedconnection, like Qt::queuedconnection, the difference is that there is a mutex at the start of the signal, waiting for the slot function to return, This way, if the slot function and the signal function in the same thread will have a deadlock (that is, stuck in the lock position, unable to enter the slot function).
Qt::uniqueconnection, this through "or" with the above to use, indicating that the same connection can only be connected once, as if there is no effect, the object, signal, slot the same connection multiple connections will fail.
Signal and slot to disconnect, use Qobject::d Isconnect method.
About the use of signals and slots is so much, but often used, especially in multi-threaded, in the case of the slot function is not executed may be the connection is wrong or the slot function where the thread is blocked (such as a dead loop).
Quick start of Qt quick signal, slot