Help about sleep on C++ ...
I wanted with a push button the Pixmap of a label change.. so i had write this.
Code:
void MainWindow::on_pushButton_clicked()
{
ui
->label
->setPixmap
(QPixmap(QString::fromUtf8(":/new/prefix1/1.gif")));
}
It works...
But i want after a second the label change to the previous picture again... So i had put this
Code:
void MainWindow::on_pushButton_clicked()
{
ui
->label
->setPixmap
(QPixmap(QString::fromUtf8(":/new/prefix1/1.gif")));
system("sleep 1");
ui
->label
->setPixmap
(QPixmap(QString::fromUtf8(":/new/prefix1/2.jpg")));
}
But it doesn't work... I think what it does is first sleep for one second and then change both pictures.... What should i do?
Re: Help about sleep on C++ ...
You have to use a QTimer. Connect its timeout signal with a slot where you set back the image.
Re: Help about sleep on C++ ...
Quote:
Originally Posted by
Bong.Da.City
But it doesn't work... I think what it does is first sleep for one second and then change both pictures.... What should i do?
by the way... your code work! But unfortunately you would not see the results. With the system call you block your application. The application has to go back in event processing (main loop) to draw the new image.
You can do something like that instead of the system sleep:
Code:
t.start();
while(t.elapsed() < 1000) {
}
}
But in this case, this is techosexual. The suggestion from Lykrug is a much better solution.
Re: Help about sleep on C++ ...
An you are sure that sleep takes seconds rather than milliseconds....
Re: Help about sleep on C++ ...
I assume sleep from the GNU coreutils. This sleep will take seconds as argument.