Query Related to Waiting Timer Class
-
@Maaz-Momin yeah sure......here i explain it!
Steps how modem will work :
Step-1 : Qt will send first send command to Modem
Step-2 : Modem will give response as a reply to that command
Step-3 : Now I have to wait for a specific time period (say 10 seconds) maximum to receive the response. If I get response within 10 seconds I will move to next command, else I will quit this slot.I want to call slot1() recursively , because I have to wait for a maximum time of 10 seconds in order to receive response else I will quit.
UART has nothing to do with this. I have removed it infact!
-
The response of modem will be received in some other function i believe as slot (assume "messageReceiveSlot").
In that case,
- Create a global timer.
- When slot1() is called
a) send command to modem.
b) Set timer interval to 10sec and singleShot property to true. - On message received before timeout stop your timer and call slot2() OR 4) On timeOut give time out message and disconnect your messageReceiveSlot
If my assumption is incorrect then let me know.
-
@Maaz-Momin Thanks.
I have implemented a different logic. I have extracted the real time values of second and stored that in some variable(let k) And then I have called the same function recursively till real time second value is not greater than (k+10).
Once real time seconds value exceeds (K+10), I will declare timeout. -
How do you extract real time values of second?
-
@Maaz-Momin quite simple.
QTime time =QTime::currentTime();
QString second_time= time.toString("ss"); // store seconds value in string
secondvalue=second_time.toInt(); // converted string into int -
Is this code written in slot1? Because at the end it is working somewhat similar to QTimer which is already provided to you by QT.
-
@Maaz-Momin yeah i have written it in the slot.And it is the use of QTimer Class only.
-
Can you paste your code here. I want to have a look. In my opinion you are making this even more complex.
-
@Maaz-Momin ok
here it is :int secondvalue=0; int secondsCompare=0; int onlyOnce=0; void MainWindow::on_pushButton_clicked() { QTime time =QTime::currentTime(); QString second_time= time.toString("ss"); secondvalue=second_time.toInt(); if(onlyOnce==1) { secondsCompare=secondvalue; // second value stored in secondsCompare onlyOnce++; } if(secondvalue == (secondsCompare+10)) { slot2(); //call timeout slot } else { if(execute_once==1) { sendModem Command1; } int Response_returnValue=0; Response_returnValue= return from modem analysis function if(Response_returnValue==1) //for ok response { slot3(); //go for next commad } else // response not received { on_pushButton_clicked(); // call recursively } } } void MainWindow::slot2) { send command2; } void MainWindow::slot3) { show timeout message in label; }
-
Code can be improved for performance. But if you are fine then it's good. Because this for sure, will call MainWindow::on_pushButton_clicked() a lot of time.
Edit: Also if it works can you mark it as SOLVED.