Reputation: 767
I'm using Qt for an application. I would like to display a window then put a timer and display a second window. But currently the timer is done then the 2 windows open at the same time
this->firstWindow->show();
QTime dieTime = QTime::currentTime().addSecs(10);
while (QTime::currentTime() < dieTime);
this->secondWindow->show();
I tried a lot of solutions, like putting the show() of the firstwindow directly into the constructor but nothing works.
Upvotes: 1
Views: 162
Reputation: 5579
You are using a blocking while
loop to wait for the time to elapse, so the GUI thread cannot update the user interface. You could use QTimer
for a non-blocking wait or refresh the GUI by adding qApp->processEvents(QEventLoop::AllEvents, 100);
into the while
loop.
I would prefer QTimer
, because then you are not creating your own event loop. For example:
QTimer::singleShot(10000, this->secondWindow, SLOT(show()));
Upvotes: 3