Manual loop
-
Hello,
I was wondering whether it's possible to manually call everything that QApplication::exec() calls in a loop myself.
For example:void main_loop() { MyOwnApp::DoAThing(); QApplication::draw(); QApplication::pollEvents(); MyOwnApp::DoSomething(); }
Rather than having to use QApplication::exec() or run()
-
That's quite a deep question :-) If you don't get any answers here, consider asking on Qt interest mailing list. Qt core devs reside there and they should be able to help you. https://lists.qt-project.org/listinfo/interest
I'll start by saying that I don't know the answer. What follows are my guesses. I think that it likely won't work - QCoreApplication is a singleton, and user code can call
processEvents()
at any point, which would go around your custom loop. You may have more luck if you handle events yourself in a custom event dispatcher. See setEventDispatcher() and QAbstractEventDispatcher. -
@Mehodin said in Manual loop:
QApplication::processEvents()
Please note that using this method can be quite dangerous at times. It's better, if you can, to spin a custom QEventLoop, use QThread or make your code asynchronous (based on signals and slots).
-
@Mehodin said in Manual loop:
I uhh, i actually managed to find what i need by simply calling QApplication::processEvents() in a while loop, somehow that was enough so the UI would keep running and wouldn't deadlock
Please don‘t, with each call to processEvents() a fairy dies !