Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Infinite condition checking
Qt 6.12 LTS is out! See what's new in the release blog

Infinite condition checking

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 4 Posters 3.6k Views 3 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #8

    Sounds like a simple QTimer that calls foo regularly should do the job.

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

    H 1 Reply Last reply
    3
    • SGaistS SGaist

      Sounds like a simple QTimer that calls foo regularly should do the job.

      H Offline
      H Offline
      hbatalha
      wrote on last edited by
      #9

      @SGaist That did solve my problem, thanks

      void SomeClass::foo()
      {
          if( ! condition)
          {
              QTimer::singleShot(5000, this, &SomeClass::foo);
      
              return;
          }
      ...
      
      }
      
      1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #10

        You might want to consider making a QTimer member variable to be able to stop it for example when your application ends.

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

        H 1 Reply Last reply
        0
        • SGaistS SGaist

          You might want to consider making a QTimer member variable to be able to stop it for example when your application ends.

          H Offline
          H Offline
          hbatalha
          wrote on last edited by
          #11

          @SGaist didn't quite understand what you meant, when my application won't everything be stopped?

          Also, I need to call foo only once when the timeout is emitted, took that example from the documentation.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #12

            I don't know how long foo will take so you might not want for it to triggered when you end your application. Ending an application does not mean everything is destroyed instantly.

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

            H 2 Replies Last reply
            0
            • SGaistS SGaist

              I don't know how long foo will take so you might not want for it to triggered when you end your application. Ending an application does not mean everything is destroyed instantly.

              H Offline
              H Offline
              hbatalha
              wrote on last edited by
              #13

              @SGaist foo is not from the mainwindow, is part of another class, should I call stop in the destructor?

              jsulmJ 1 Reply Last reply
              0
              • H hbatalha

                @SGaist foo is not from the mainwindow, is part of another class, should I call stop in the destructor?

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #14

                @hbatalha said in Infinite condition checking:

                is part of another class

                Then put it there as member variable and stop it in destructor (or whenever needed).

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

                H 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @hbatalha said in Infinite condition checking:

                  is part of another class

                  Then put it there as member variable and stop it in destructor (or whenever needed).

                  H Offline
                  H Offline
                  hbatalha
                  wrote on last edited by
                  #15

                  @jsulm ok thanks

                  1 Reply Last reply
                  0
                  • SGaistS SGaist

                    I don't know how long foo will take so you might not want for it to triggered when you end your application. Ending an application does not mean everything is destroyed instantly.

                    H Offline
                    H Offline
                    hbatalha
                    wrote on last edited by
                    #16

                    @SGaist @jsulm

                    Ending an application does not mean everything is destroyed instantly.

                    I have followed your suggestion, and now I am wondering, is this something that I have to always watch out for, is there a name for this kind of situation, a reference I can search?

                    And also, why is everything not destroyed instantly? What are the steps being taken? What is happening under the hood there? Any reference?

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #17

                      Order of destruction, code run during destruction, etc

                      Think of a database, you likely appreciate the fact that all operations are finalised before it stops so you don't have corrupted data when you restart 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
                      1

                      • Login

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