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)