Unsolved QDialog showing busy while loop is running
-
I have a problem figuring out how I should solve my problem.
I made my own QDialog which I execute open() on.
And then run my while loop, the problem is that this way the QDialog is black/transparent in the cases I've tried.I want it to run and show a Cancel button with a spinning indiator while my loop is running.
Therefore .exec() isn't the solution since then it wouldn't run my loop.QDialog dlg dlg.show(); while (true) { //do stuff }
What would be the best solution here?
-
@mikael-larsson said in QDialog showing busy while loop is running:
What would be the best solution here?
Don't block the event loop. What are you doing in your while loop?
-
Never run "endless" loops (anything which takes longer than the blink of your eyes) in your GUI thread. This will freeze your GUI. Either you can split your do-stuff-task in small chunks - then you can pack it in a QTimer callback and start the timer with zero delay - or you have to learn true multi threading. See for example https://doc.qt.io/qt-5/threads-technologies.html as a starting point.
-
@Christian-Ehrlicher running an external program where I wait for it to finish.
I was hoping theere would be an easy solution, if I had any progress I could just have ran QProgressDialog but since I have no indication on how far the progress have come I'm stuck with just saying that the program is running.
-
@mikael-larsson said in QDialog showing busy while loop is running:
running an external program where I wait for it to finish
There is no reason to "wait" for it to finish - there is https://doc.qt.io/qt-5/qprocess.html#finished signal.