Unsolved Waiting x seconds before continuing
-
You should take a look at the documentation to of QTimer - there is an example which does exactly what you want to do: https://doc.qt.io/qt-5/qtimer.html#details
-
@Christian-Ehrlicher sorry but which one is the example?
-
@John-Green
Hi
I assume he meant the singleslot example.
Its perfect fit anyway.QTimer::singleShot(1000, this, [this](){ this->ui->label->setText("BACK"); });
this sets label to "BACK" after 1 sec.
we are using the static function version so we avoid to
new QTimer and also delete it again.
singleShot is perfect for such delay.Also, please dont use sleep in GUI thread. it will just hang whole app and never
really do what you want. -
@mrjj Hi thanks for the help however this piece of code throws no matching function call error, any ideas why?
-
@John-Green
Did you include
#include <QTimer>
?
please post the actual error :) -
@mrjj yes I have it included
error: no matching function for call to 'QTimer::singleShot(int, MainWindow*, MainWindow::on_Button_clicked()::<lambda()>)'
});
^ -
@John-Green
Hi
Can you show the actual code ?
Im using a lambda, but it seems you used normal slot ?
(which is also possible)MainWindow::on_Button_clicked()::<lambda()>
looks like you tell it the lambda is in mainwindow so syntax might be wrong :) -
@mrjj I just used the code you provided and didn't change anything:
QTimer::singleShot(1000, this, [this](){ this->ui->label->setText("BACK"); });
-
@John-Green
That is odd.
Are you using an older Qt / compiler ?
Lambdas came later.Anyway, you can also use a normal slot if you want
QTimer::singleShot(1000, this, &MainWindow::on_pushButton_5_released);
-
Hi,
To add to @mrjj, which version of Qt are you using ?