c++ - How do I process events on a QThread? -


normally if in process intensive function can call qcoreapplication::processevents() or qeventloop::processevents() ensure processing doesn't block other signals , slots.

however, if create new qthread , move worker thread, don't have qcoreapplication or qeventloop call processevents().

from research, seems should able install qeventloop on new qthread created, , can call processevents() on qeventloop.

however, can't figure out how this. figure might this:

qthread *thread = new qthread(this); worker *worker = new worker(this); qeventloop *loop = new qeventloop();  connect(thread, signal(finished()), worker, slot(deletelater())); connect(thread, signal(finished()), thread, slot(deletelater())); connect(thread, signal(started()), worker, slot(startprocessing())); connect(worker, signal(done()), thread, slot(quit())); connect(worker, signal(done()), loop, slot(quit()));  worker->movetothread(thread);      //loop->exec() // blocks processing of thread loop->movetothread(thread);  //loop->exec() // loop not member of thread anymore ,                // if was, block thread starting thread->start(); //loop->exec(); // loop not member of thread anymore ,                 // if was, block thread continuing 

every place try start loop has sort of issue. if worked, how call processevents() on qeventloop()?

alternatively, qthread has function seteventdispatcher() , qabstracteventdispatcher has processevents() function, can't seem find subclasses qabstracteventdispatcher.

what proper way process events during intensive worker function on qthread?

according documentation, calling qcoreapplication::processevents() processes events whichever thread called it.


Comments