QT delay not working
-
Hi
It is not good to use QThread::msleep();
in a GUI program as you completely freeze all drawing and input and
it not suitable for any kind of delay in any sort of animation.In this case, a single shot timer is good for such a delay.
QTimer::singleShot(1000, [ this]{
qDebug("Hello from lambda");
ui->pushButtonFeeder->setStyleSheet("font-size: 20px;""background: green;");
ui->pushButtonFeeder->setText("FEEDER ON");
});@mrjj this working for me..but
1.if i give same delay value it exicute at the same time
QTimer::singleShot(1000, [ this]{
qDebug("Hello from lambda");
ui->pushButton1->setStyleSheet("font-size: 20px;""background: green;");
ui->pushButton1->setText("FEEDER ON");
});
QTimer::singleShot(1000, [ this]{
qDebug("Hello from lambda");
ui->pushButton2->setStyleSheet("font-size: 20px;""background: green;");
ui->pushButton2->setText("FEEDER ON");
});
2.if give different time value the it works
QTimer::singleShot(500, [ this]{
qDebug("Hello from lambda");
ui->pushButton1->setStyleSheet("font-size: 20px;""background: green;");
ui->pushButton1->setText("FEEDER ON");
});
QTimer::singleShot(1000, [ this]{
qDebug("Hello from lambda");
ui->pushButton2->setStyleSheet("font-size: 20px;""background: green;");
ui->pushButton2->setText("FEEDER ON");
}); -
@mrjj this working for me..but
1.if i give same delay value it exicute at the same time
QTimer::singleShot(1000, [ this]{
qDebug("Hello from lambda");
ui->pushButton1->setStyleSheet("font-size: 20px;""background: green;");
ui->pushButton1->setText("FEEDER ON");
});
QTimer::singleShot(1000, [ this]{
qDebug("Hello from lambda");
ui->pushButton2->setStyleSheet("font-size: 20px;""background: green;");
ui->pushButton2->setText("FEEDER ON");
});
2.if give different time value the it works
QTimer::singleShot(500, [ this]{
qDebug("Hello from lambda");
ui->pushButton1->setStyleSheet("font-size: 20px;""background: green;");
ui->pushButton1->setText("FEEDER ON");
});
QTimer::singleShot(1000, [ this]{
qDebug("Hello from lambda");
ui->pushButton2->setStyleSheet("font-size: 20px;""background: green;");
ui->pushButton2->setText("FEEDER ON");
});@swansorter said in QT delay not working:
if i give same delay value it exicute at the same time
Sure, because you want the second part to be delayed after the first one, right? So, after 1sec delay you do the first change, then again after 1sec more you do the second part.
-
@mrjj this working for me..but
1.if i give same delay value it exicute at the same time
QTimer::singleShot(1000, [ this]{
qDebug("Hello from lambda");
ui->pushButton1->setStyleSheet("font-size: 20px;""background: green;");
ui->pushButton1->setText("FEEDER ON");
});
QTimer::singleShot(1000, [ this]{
qDebug("Hello from lambda");
ui->pushButton2->setStyleSheet("font-size: 20px;""background: green;");
ui->pushButton2->setText("FEEDER ON");
});
2.if give different time value the it works
QTimer::singleShot(500, [ this]{
qDebug("Hello from lambda");
ui->pushButton1->setStyleSheet("font-size: 20px;""background: green;");
ui->pushButton1->setText("FEEDER ON");
});
QTimer::singleShot(1000, [ this]{
qDebug("Hello from lambda");
ui->pushButton2->setStyleSheet("font-size: 20px;""background: green;");
ui->pushButton2->setText("FEEDER ON");
});Hi
Yes it is executed when time is gone.Im not really sure what you are trying but it seems you want more than one button to change
color ? -
Hi
Yes it is executed when time is gone.Im not really sure what you are trying but it seems you want more than one button to change
color ?@mrjj i want like this
1.ui->pushButton1->setStyleSheet("font-size: 20px;""background: green;");
ui->pushButton1->setText("FEEDER ON");
delay(1000);
after 1 sec delay
2.
ui->pushButton2->setStyleSheet("font-size: 20px;""background: green;");
ui->pushButton2->setText("FEEDER ON");
delay(1000);another 1sec delay
3.
ui->pushButton3->setStyleSheet("font-size: 20px;""background: green;");
ui->pushButton3->setText("FEEDER ON") -
@mrjj i want like this
1.ui->pushButton1->setStyleSheet("font-size: 20px;""background: green;");
ui->pushButton1->setText("FEEDER ON");
delay(1000);
after 1 sec delay
2.
ui->pushButton2->setStyleSheet("font-size: 20px;""background: green;");
ui->pushButton2->setText("FEEDER ON");
delay(1000);another 1sec delay
3.
ui->pushButton3->setStyleSheet("font-size: 20px;""background: green;");
ui->pushButton3->setText("FEEDER ON") -
Hi,
I thing is not a good idea to use Qthread::msleep in this way for GUI, as someone has already suggested you I should use Qtimer::singleShot.Only for test, have you tried with update function before msleep?
ui->pushButtonSystemswitchon->setStyleSheet("font-size: 20px;" "background: red;"); ui->pushButtonSystemswitchon->setText("ON"); ui->pushButtonFeeder->setEnabled(false); ui→pushButtonEejecter→setEnabled(false);
ui→pushButtonSystemswitchon→update();
ui→pushButtonSystemswitchon→update();
ui→pushButtonFeeder→update();
ui→pushButtonEejecter→update();QThread::msleep(1000);
-
@mrjj am asking is their any other way ?
-
@mrjj am asking is their any other way ?
@swansorter Why do you need other way? What is wrong with QTimer::singleShot and delays of 1000 and 2000?
-
@swansorter Why do you need other way? What is wrong with QTimer::singleShot and delays of 1000 and 2000?
@jsulm i dnt know weather it is correct way or not
-
@mrjj thank you very much