Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. India
  4. Query Related to Waiting Timer Class

Query Related to Waiting Timer Class

Scheduled Pinned Locked Moved Solved India
12 Posts 2 Posters 2.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Maaz Momin
    18 Dec 2018, 09:34

    @SHUBHAM-SINGH-RAO said in Query Related to Waiting Timer Class:

    Not sure, the aim says that you want to receive the data in specific time period, while the first command of slot1() sends something to modem. Why do you want to call slot1() recursively? I am not aware about how UART works, can simplify it for me.

    S Offline
    S Offline
    SHUBHAM SINGH RAO
    wrote on 18 Dec 2018, 09:59 last edited by
    #3

    @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!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Maaz Momin
      wrote on 18 Dec 2018, 11:08 last edited by Maaz Momin
      #4

      The response of modem will be received in some other function i believe as slot (assume "messageReceiveSlot").

      In that case,

      1. Create a global timer.
      2. When slot1() is called
        a) send command to modem.
        b) Set timer interval to 10sec and singleShot property to true.
      3. 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.

      S 1 Reply Last reply 19 Dec 2018, 05:09
      3
      • M Maaz Momin
        18 Dec 2018, 11:08

        The response of modem will be received in some other function i believe as slot (assume "messageReceiveSlot").

        In that case,

        1. Create a global timer.
        2. When slot1() is called
          a) send command to modem.
          b) Set timer interval to 10sec and singleShot property to true.
        3. 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.

        S Offline
        S Offline
        SHUBHAM SINGH RAO
        wrote on 19 Dec 2018, 05:09 last edited by SHUBHAM SINGH RAO
        #5

        @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.

        1 Reply Last reply
        1
        • M Offline
          M Offline
          Maaz Momin
          wrote on 19 Dec 2018, 05:19 last edited by
          #6

          How do you extract real time values of second?

          S 1 Reply Last reply 19 Dec 2018, 05:24
          1
          • M Maaz Momin
            19 Dec 2018, 05:19

            How do you extract real time values of second?

            S Offline
            S Offline
            SHUBHAM SINGH RAO
            wrote on 19 Dec 2018, 05:24 last edited by
            #7

            @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

            1 Reply Last reply
            0
            • M Offline
              M Offline
              Maaz Momin
              wrote on 19 Dec 2018, 05:33 last edited by
              #8

              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.

              S 1 Reply Last reply 19 Dec 2018, 05:47
              0
              • M Maaz Momin
                19 Dec 2018, 05:33

                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.

                S Offline
                S Offline
                SHUBHAM SINGH RAO
                wrote on 19 Dec 2018, 05:47 last edited by
                #9

                @Maaz-Momin yeah i have written it in the slot.And it is the use of QTimer Class only.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  Maaz Momin
                  wrote on 19 Dec 2018, 05:49 last edited by
                  #10

                  Can you paste your code here. I want to have a look. In my opinion you are making this even more complex.

                  S 1 Reply Last reply 19 Dec 2018, 06:21
                  0
                  • M Maaz Momin
                    19 Dec 2018, 05:49

                    Can you paste your code here. I want to have a look. In my opinion you are making this even more complex.

                    S Offline
                    S Offline
                    SHUBHAM SINGH RAO
                    wrote on 19 Dec 2018, 06:21 last edited by SHUBHAM SINGH RAO
                    #11

                    @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;
                    }
                    
                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      Maaz Momin
                      wrote on 19 Dec 2018, 07:28 last edited by Maaz Momin
                      #12

                      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.

                      1 Reply Last reply
                      1

                      12/12

                      19 Dec 2018, 07:28

                      • Login

                      • Login or register to search.
                      12 out of 12
                      • First post
                        12/12
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved