Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTimer make traitement out of for loop ?
Forum Updated to NodeBB v4.3 + New Features

QTimer make traitement out of for loop ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
30 Posts 6 Posters 3.1k Views 2 Watching
  • 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.
  • I Offline
    I Offline
    imene
    wrote on 27 Aug 2022, 14:34 last edited by
    #1

    Hi,
    what i have to do to keep the traitement inside qtimer tirning without passing to the next if condition here ?

    for(..)
    {
    if(..){ 
    QTimer::singleShot(6000, [=](){
                        qDebug()<<"Timer on do something after 6 second...";
    
    
                   // i want to set a time out condition here
    
                   });//timer ends here
    }//end if
    else
    {..}
    }//end for
    
    J 1 Reply Last reply 27 Aug 2022, 15:25
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 27 Aug 2022, 15:13 last edited by
      #2

      Hi,

      Are you asking to block the code in that if block until the timer times out and the lambda is finished ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      I 1 Reply Last reply 27 Aug 2022, 18:26
      0
      • I imene
        27 Aug 2022, 14:34

        Hi,
        what i have to do to keep the traitement inside qtimer tirning without passing to the next if condition here ?

        for(..)
        {
        if(..){ 
        QTimer::singleShot(6000, [=](){
                            qDebug()<<"Timer on do something after 6 second...";
        
        
                       // i want to set a time out condition here
        
                       });//timer ends here
        }//end if
        else
        {..}
        }//end for
        
        J Offline
        J Offline
        JonB
        wrote on 27 Aug 2022, 15:25 last edited by
        #3

        @imene
        Please don't post multiple questions for the same thing, your https://forum.qt.io/topic/138912/how-can-i-set-time-out-condition-in-the-timer, it's not fair on the duplicated effort you may get people to do.

        I 1 Reply Last reply 27 Aug 2022, 18:27
        0
        • S SGaist
          27 Aug 2022, 15:13

          Hi,

          Are you asking to block the code in that if block until the timer times out and the lambda is finished ?

          I Offline
          I Offline
          imene
          wrote on 27 Aug 2022, 18:26 last edited by
          #4

          @SGaist yes exactelly

          1 Reply Last reply
          0
          • J JonB
            27 Aug 2022, 15:25

            @imene
            Please don't post multiple questions for the same thing, your https://forum.qt.io/topic/138912/how-can-i-set-time-out-condition-in-the-timer, it's not fair on the duplicated effort you may get people to do.

            I Offline
            I Offline
            imene
            wrote on 27 Aug 2022, 18:27 last edited by imene
            #5

            @JonB Sorry i just i wanted to make it more clear here i will delete the other topic

            J 1 Reply Last reply 28 Aug 2022, 06:29
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 27 Aug 2022, 18:43 last edited by
              #6

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • I imene
                27 Aug 2022, 18:27

                @JonB Sorry i just i wanted to make it more clear here i will delete the other topic

                J Offline
                J Offline
                JonB
                wrote on 28 Aug 2022, 06:29 last edited by
                #7

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

                1 Reply Last reply
                1
                • I Offline
                  I Offline
                  imene
                  wrote on 28 Aug 2022, 17:07 last edited by imene
                  #8

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

                  J 1 Reply Last reply 28 Aug 2022, 17:19
                  1
                  • I imene
                    28 Aug 2022, 17:07

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

                    J Offline
                    J Offline
                    JonB
                    wrote on 28 Aug 2022, 17:19 last edited by
                    #9

                    @imene
                    Not a problem :) Actually it looks like I remembered wrong and people had not started responding in that thread!

                    1 Reply Last reply
                    1
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 28 Aug 2022, 18:19 last edited by
                      #10

                      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.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      I 1 Reply Last reply 28 Aug 2022, 19:09
                      1
                      • S SGaist
                        28 Aug 2022, 18:19

                        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.

                        I Offline
                        I Offline
                        imene
                        wrote on 28 Aug 2022, 19:09 last edited by
                        #11

                        @SGaist good like this method preposed by @mpergand here (https://forum.qt.io/topic/138912/how-can-i-set-time-out-condition-in-the-timer-duplicated-https-forum-qt-io-topic-138913-qtimer-make-traitement-out-of-for-loop/3)

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 28 Aug 2022, 20:04 last edited by
                          #12

                          That's one way of implementing it.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • I Offline
                            I Offline
                            imene
                            wrote on 28 Aug 2022, 22:35 last edited by imene
                            #13

                            @SGaist is there a way more easy than that ? with another type of timer ?
                            can i use this signal void QTimer::timeout()?

                            M 1 Reply Last reply 28 Aug 2022, 23:41
                            0
                            • I imene
                              28 Aug 2022, 22:35

                              @SGaist is there a way more easy than that ? with another type of timer ?
                              can i use this signal void QTimer::timeout()?

                              M Offline
                              M Offline
                              mpergand
                              wrote on 28 Aug 2022, 23:41 last edited by mpergand
                              #14

                              @imene
                              For your long delay, you can use lambda as well,
                              Although I don't see any real benefit with it.

                              1 Reply Last reply
                              0
                              • I Offline
                                I Offline
                                imene
                                wrote on 29 Aug 2022, 10:09 last edited by
                                #15

                                @mpergand
                                What do you mean with lamba ?

                                J 1 Reply Last reply 29 Aug 2022, 11:25
                                0
                                • I imene
                                  29 Aug 2022, 10:09

                                  @mpergand
                                  What do you mean with lamba ?

                                  J Online
                                  J Online
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on 29 Aug 2022, 11:25 last edited by
                                  #16

                                  @imene C++ lambda functions: https://en.cppreference.com/w/cpp/language/lambda

                                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 Reply Last reply
                                  1
                                  • I Offline
                                    I Offline
                                    imene
                                    wrote on 29 Aug 2022, 13:34 last edited by
                                    #17

                                    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 .

                                    C 1 Reply Last reply 29 Aug 2022, 13:35
                                    0
                                    • I imene
                                      29 Aug 2022, 13:34

                                      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 .

                                      C Offline
                                      C Offline
                                      Christian Ehrlicher
                                      Lifetime Qt Champion
                                      wrote on 29 Aug 2022, 13:35 last edited by
                                      #18

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

                                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                      Visit the Qt Academy at https://academy.qt.io/catalog

                                      1 Reply Last reply
                                      0
                                      • I Offline
                                        I Offline
                                        imene
                                        wrote on 29 Aug 2022, 13:47 last edited by
                                        #19

                                        @Christian-Ehrlicher how ?

                                        C 1 Reply Last reply 29 Aug 2022, 13:54
                                        0
                                        • I imene
                                          29 Aug 2022, 13:47

                                          @Christian-Ehrlicher how ?

                                          C Offline
                                          C Offline
                                          Christian Ehrlicher
                                          Lifetime Qt Champion
                                          wrote on 29 Aug 2022, 13:54 last edited by Christian Ehrlicher
                                          #20

                                          @imene said in QTimer make traitement out of for loop ?:

                                          how ?

                                          if (yourCoditionIsMet) {
                                            doSomethingYouWant()
                                          }
                                          

                                          maybe?

                                          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                          Visit the Qt Academy at https://academy.qt.io/catalog

                                          1 Reply Last reply
                                          0

                                          8/30

                                          28 Aug 2022, 17:07

                                          22 unread
                                          • Login

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