[SOLVED] Wait for timeout or some signal
-
Yeah, it forces the QCoreApplication instance to process events in the event queue, including signals and slots provided by MOC. This way, the loop does not block operation of the app.
-
tnx, i note that!
-
Or, look into "QxtSignalWaiter":http://libqxt.bitbucket.org/doc/0.6/qxtsignalwaiter.html from the libQxt library.
-
tnx a lot!
-
Calling processEvents() in a loop like proposed will keep your CPU 100% bussy, because you just keep polling the event queue. Using an eventloop is a smarter solution that doesn't waste CPU cycles like that, so it will not spike your CPU. It is also the solution implemented by the libQxt in QxtSignalWaiter.
-
QxtSignalWaiter is implemented with a help of processEvents, not eventLoop. See "here":http://dev.libqxt.org/libqxt/src/21ea5919eabb2a404eafdffcdb8383472ca66bdd/src/core/qxtsignalwaiter.cpp?at=master#cl-143.
-
[quote author="RomaHagen" date="1357227120"]QxtSignalWaiter is implemented with a help of processEvents, not eventLoop. See "here":http://dev.libqxt.org/libqxt/src/21ea5919eabb2a404eafdffcdb8383472ca66bdd/src/core/qxtsignalwaiter.cpp?at=master#cl-143. [/quote]
Hmmm... You're right. Surprising. Thanks for the correction.
Does anyone know why Qxt choose this implementation instead?
-
See "this":http://dev.libqxt.org/libqxt/src/21ea5919eabb2a404eafdffcdb8383472ca66bdd/src/core/qxtsignalwaiter.cpp?at=master#cl-143 and read the doc about WaitForMoreEvents "here":http://qt-project.org/doc/qt-4.8/qeventloop.html#ProcessEventsFlag-enum.
-
Yes, I know where to find the sources and I know the docs, but that was not my question. I sometimes use this idea:
@
QEventLoop loop;
connect(myObject, SIGNAL(theSignalToWaitFor()), &loop, SLOT(quit()));
connect(timeoutTimer, SIGNAL(timeout()), &loop, SLOT(quit()));
loop.exec(); //blocks untill either theSignalToWaitFor or timeout was fired
@ -
[quote author="Andre" date="1357286986"]Yes, I know where to find the sources and I know the docs, but that was not my question. I sometimes use this idea:
@
QEventLoop loop;
connect(myObject, SIGNAL(theSignalToWaitFor()), &loop, SLOT(quit()));
connect(timeoutTimer, SIGNAL(timeout()), &loop, SLOT(quit()));
loop.exec(); //blocks untill either theSignalToWaitFor or timeout was fired
@[/quote]
thank you. it's very useful.