c++ - Why message loop doesn't block the GUI in windows app but does in Qt? -


i'm working on program using qt, , of code based on windows samples. problem i'm having, , don't quite understand how same code block qt gui while work totally fine in windows app.

here's example. have program gets data camera, processing on it, displays on screen. in windows sample there's this:

// create event these self-explanatory parameters // event signals when next frame ready process handle frameevent  = createevent(nullptr, true, false, nullptr)  // run while loop magically doesn't block handle hevents[1];  while (wm_quit != msg.message) {   hevents[0] = frameevent;    dword dwevent = msgwaitformultipleobjects(1, hevents, false, infinite, qs_allinput);    // if have our event run processing   if (wait_object_0 == dwevent)   {     update();   }   // else handle input or whatever } 

the update function looks this:

if (wait_object_0 = waitforsingleobject(frameevent, 0) {   gettheframe();   processtheframe();   drawtheframe(); } 

if try implement same way in qt freeze , while loop run forever. solution i've got run loop in separate thread (qthread) , emit signal when new frame ready, this:

void worker::run() {     running_ = true;      while (running_)     {         if (waitforsingleobject(frameevent, 0) == wait_object_0)         {             emit signalframe();         }          // necessary or still freeze!         usleep(15);     } } 

the signal connected slot similar job update() method windows sample.

now, works fine, long processing single frame can done before next frame available.

as processing went more complex , slower camera framerate, program stops responding. exact same code in windows sample still works fine, framerate drops, drawn , gui remains responsive.

could explain going on, , may possible solution?

the win32 version calls msgwaitformultipleobjects. name should imply, waits either specified objects signaled or window message (and since it's called qs_allinput, any window message). presumably code dispatches window message afterward.

your version calls waitforsingleobject. name should imply, waits on only specified object. won't unblock on window messages.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -