Changing the UI in a non-UI thread (Delphi uses a hidden window to process, QT uses a signal slot)

Source: Internet
Author: User

In Delphi I remember the use of Tthread.synchronize (Tthreadmethod), the principle is to use a hidden window to deal with.

In QT debug mode, the same problem is encountered, showing the error:

Cannot send events to objects owned by a different thread

The solution is to use the signal slot, which is the constant signal in the thread, and the slot function of the UI threads is constantly receiving signals and processing:

So as a solution I would propose the following:

    • Define a signal in your Paintthread class
    • Connect this signal to the paint () slot in Qwidget subclass
    • Emit it in the run () function

Reference: Http://stackoverflow.com/questions/9018434/qthread-doesnt-work-well

or use:

int threadtest::showprogress (int percent, void *pcontext)
{
Instead of:someotherqobject->updateprogress (percent);
Qmetaobject::invokemethod (Someotherqobject,//obj
SLOT (updateprogress (int)),//Member
Qt::queuedconnection,//connection type
Q_arg (int, percent)); Val1

Qdebug () << "Progress:" << qstring::number (percent);
return 0;
}

https://forum.qt.io/topic/9119/ Solved-how-can-i-evade-the-error-cannot-send-events-to-objects-owned-by-a-different-thread/4

Changing the UI in a non-UI thread (Delphi uses a hidden window to process, QT uses a 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.