QT multi-threaded signal slot transmission mode

Source: Internet
Author: User

A brief introduction to how the QT signal is connected to the slot:
Qt::autoconnection means that the system automatically chooses the appropriate connection mode, if the signal and slot on the same thread, the use of QT::D irectconnection,
If the signal is not on the same thread as the slot, the Qt::queuedconnection connection will be used.
Qt::D irectconnection indicates that the slot function is executed immediately once the signal is generated.
Qt::queuedconnection indicates that after the signal is generated, the event will be sent to the thread where your receiver is located, postevent (Qevent::metacall,...),
The slot function is processed in the event loop of the thread where receiver is located.
Qt::blockingqueuedconnection indicates that the signal is generated after calling Sendevent (Qevent::metacall,...),
The receiver is not returned until the thread processing is complete, only if the sender,receiver is not on the same thread.
Qt::uniqueconnection indicates that the connection will succeed only if it is not a duplicate connection. If you have previously had a link (the same signal is connected to the same slot on the same object), the connection will fail and will return false.
Qt::autocompatconnection and QT3 Maintain compatibility
Note that for any qthread, its thread exists only in the run () function, and the other functions are not in the thread, so qt::blockingqueuedconnection is used here.
Because the Readyread () signal is emitted when the socket has data arrives, but at this point it is possible that the previous receivefile () is not finished, the qt::autoconnection used previously,
The result is that when a large file is transmitted, the error occurs because the signal is connected as soon as the data arrives, but the data reception is not processed, and the qt::blockingqueuedconnection blocks
This connection is not sent until Receivefile () has finished processing and returns.
Qdebug () << "Run Thread:" <<qthread::currentthreadid ();
Connect (tcpsocket,signal (Readyread ()), This,signal (RECEIVESGL (Tcpsocket)));
Connect (tcpsocket,signal (Readyread ()), This,slot (Receivefile ()), qt::blockingqueuedconnection);
exec ();
}

QT multi-threaded signal slot transmission mode

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.