QTimer make traitement out of for loop ?
-
When you want to make things clearer, you can simply edit your original thread message and add more information with a note stating what you added.
-
@imene said in QTimer make traitement out of for loop ?:
i will delete the other topic
And please do not do this! You had asked different questions there first, people had taken time to respond, and now you have deleted the whole topic. Once people at least respond in a topic please don't delete it; you can always mark it as Solved and raise a different topic for a different question.
-
Okay i restored it, i'm new at this Forum and i was little bit confused how to make a clear topic.
https://forum.qt.io/topic/138912/how-can-i-set-time-out-condition-in-the-timer
i'm sorry.. -
Okay i restored it, i'm new at this Forum and i was little bit confused how to make a clear topic.
https://forum.qt.io/topic/138912/how-can-i-set-time-out-condition-in-the-timer
i'm sorry.. -
Based on you other thread, I would say that you should refactor your payload processing logic.
Rather than I tight loop that you are going to block use for example invokeMethod when you are done with the processing of the current payload. That way, for that particular case, you will call invokeMethod as the last thing in you lambda to continue the processing. Your loop will otherwise continue.
-
Based on you other thread, I would say that you should refactor your payload processing logic.
Rather than I tight loop that you are going to block use for example invokeMethod when you are done with the processing of the current payload. That way, for that particular case, you will call invokeMethod as the last thing in you lambda to continue the processing. Your loop will otherwise continue.
-
That's one way of implementing it.
-
@SGaist is there a way more easy than that ? with another type of timer ?
can i use this signal void QTimer::timeout()? -
@imene C++ lambda functions: https://en.cppreference.com/w/cpp/language/lambda
-
QTimer::singleShot :This static function calls a slot after a given time interval; in my case i want the code to make the traitement inside QTimer::singleShot before it pass to make the next if condition .
@imene said in QTimer make traitement out of for loop ?:
to make the traitement inside QTimer::singleShot before it pass to make the next if condition .
Let the QTimer::singleShot() fire and check for your codition inside the slot.
-
@Christian-Ehrlicher how ?
-
@Christian-Ehrlicher how ?
@imene said in QTimer make traitement out of for loop ?:
how ?
if (yourCoditionIsMet) { doSomethingYouWant() }
maybe?
-
@Christian-Ehrlicher
my condition is to wait for QTimer::singleShot() to be executed -
@Christian-Ehrlicher
my condition is to wait for QTimer::singleShot() to be executed@imene said in QTimer make traitement out of for loop ?:
my condition is to wait for QTimer::singleShot() to be executed
Why?
If you want to stop a timer, use a QTimer object and stop it if you want. -
This timer
connect(m_speedTimer, &QTimer::timeout, this, &MainWindow::on_Send_Row_Button_clicked);
if( trameRecu[0]==trameTest[0]){ qDebug() <<"Test FF good!"; //model dialogue informing mModel->item(b, 4)->setText("FF");//ack m_speedTimer->start(8000); QTimer::singleShot(7000, [=](){ qDebug()<<"Timer on do something after 7000 msec..."; if((Send_Frame_Get_ACK_Function(SetPayloadRPM))=="FF") { qDebug() << "Send_Frame_Get_ACK_Function Pass" ; QString MySpeed=0; MySpeed = Send_Frame_Get_Speed_Function(NSetPayload); //SetPayloadMem="F504" qDebug() << " MySpeed" <<MySpeed; double MSpeed = MySpeed.toFloat(); qDebug() << " MSpeed" <<MSpeed; bool result = ((MSpeed >= 40) && (MSpeed <= 60)); qDebug() << "((MSpeed >= 40) && (MSpeed <= 60))" << result; result = ((MSpeed >= 90) && (MSpeed <= 110) ); qDebug() << "((MSpeed >= 90) && (MSpeed <= 110))" << result; result = ((MSpeed >= 490) && (MSpeed <= 520) ); qDebug() << "((MSpeed >= 490) && (MSpeed <= 520))" << result; if ((MSpeed > 40) && (MSpeed < 60) ) {mModel->item(b, 6)->setText("+50");}//result else if ((MSpeed > 90) && (MSpeed < 110)) {mModel->item(b, 6)->setText("+100");}//result else if ((MSpeed > 140) && (MSpeed < 160)) {mModel->item(b, 6)->setText("+150");}//result else if ((MSpeed > 190) && (MSpeed < 210)) {mModel->item(b, 6)->setText("+200");}//result else if ((MSpeed > 240) && (MSpeed < 260)) {mModel->item(b, 6)->setText("+100");}//result else if ((MSpeed > 290) && (MSpeed < 310)) {mModel->item(b, 6)->setText("+100");}//result else if ((MSpeed >490) && (MSpeed < 520)) {mModel->item(b, 6)->setText("+500");}//result else {mModel->item(b, 6)->setText("Error"); qDebug() << " MSpeed if" <<MSpeed;}//result } m_speedTimer->stop(); });//singleshot timer here }
m_speedTimer->start(8000);
repeat the traitement under it each 8000 but when i use m_speedTimer->stop(); it make traitement one time and stops without waiting 8000 msec!
I need a timer that make traitement after 8000msec. -
This timer
connect(m_speedTimer, &QTimer::timeout, this, &MainWindow::on_Send_Row_Button_clicked);
if( trameRecu[0]==trameTest[0]){ qDebug() <<"Test FF good!"; //model dialogue informing mModel->item(b, 4)->setText("FF");//ack m_speedTimer->start(8000); QTimer::singleShot(7000, [=](){ qDebug()<<"Timer on do something after 7000 msec..."; if((Send_Frame_Get_ACK_Function(SetPayloadRPM))=="FF") { qDebug() << "Send_Frame_Get_ACK_Function Pass" ; QString MySpeed=0; MySpeed = Send_Frame_Get_Speed_Function(NSetPayload); //SetPayloadMem="F504" qDebug() << " MySpeed" <<MySpeed; double MSpeed = MySpeed.toFloat(); qDebug() << " MSpeed" <<MSpeed; bool result = ((MSpeed >= 40) && (MSpeed <= 60)); qDebug() << "((MSpeed >= 40) && (MSpeed <= 60))" << result; result = ((MSpeed >= 90) && (MSpeed <= 110) ); qDebug() << "((MSpeed >= 90) && (MSpeed <= 110))" << result; result = ((MSpeed >= 490) && (MSpeed <= 520) ); qDebug() << "((MSpeed >= 490) && (MSpeed <= 520))" << result; if ((MSpeed > 40) && (MSpeed < 60) ) {mModel->item(b, 6)->setText("+50");}//result else if ((MSpeed > 90) && (MSpeed < 110)) {mModel->item(b, 6)->setText("+100");}//result else if ((MSpeed > 140) && (MSpeed < 160)) {mModel->item(b, 6)->setText("+150");}//result else if ((MSpeed > 190) && (MSpeed < 210)) {mModel->item(b, 6)->setText("+200");}//result else if ((MSpeed > 240) && (MSpeed < 260)) {mModel->item(b, 6)->setText("+100");}//result else if ((MSpeed > 290) && (MSpeed < 310)) {mModel->item(b, 6)->setText("+100");}//result else if ((MSpeed >490) && (MSpeed < 520)) {mModel->item(b, 6)->setText("+500");}//result else {mModel->item(b, 6)->setText("Error"); qDebug() << " MSpeed if" <<MSpeed;}//result } m_speedTimer->stop(); });//singleshot timer here }
m_speedTimer->start(8000);
repeat the traitement under it each 8000 but when i use m_speedTimer->stop(); it make traitement one time and stops without waiting 8000 msec!
I need a timer that make traitement after 8000msec.@imene said in QTimer make traitement out of for loop ?:
t make traitement one time and stops without waiting 8000 msec!
Then remember that you want to stop your timer after the next timeout and stop it then.