Quick start of Qt quick signal, slot

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.