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. How to stop a QTimer::singleShot

How to stop a QTimer::singleShot

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 50.5k Views 1 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.
  • L Offline
    L Offline
    luca
    wrote on last edited by
    #1

    Hi all,
    in my application I sometimes start a QTimer::singleShot but in some situation I need to stop it before it trigger.

    Is it possibile to stop it?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      "QTimer::stop() ":http://doc.qt.nokia.com/4.7/qtimer.html#stop does not work?

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • L Offline
        L Offline
        luca
        wrote on last edited by
        #3

        [quote author="Volker" date="1301580963"]"QTimer::stop() ":http://doc.qt.nokia.com/4.7/qtimer.html#stop does not work?[/quote]

        I start it with:
        @
        QTimer::singleShot(360000, this, SLOT(mySlot()));
        @

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          As long as you keep a reference to the timer, you can stop it. If you used the static function to trigger the single shot, you're out of luck (well, I guess you could come up with a hack, but please don't).

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            Sorry, I misread singleShot with setSingleShot :-(

            In this case you'll have to stick to the solutions Andre mentioned.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              [quote author="Luca" date="1301581026"]
              [quote author="Volker" date="1301580963"]"QTimer::stop() ":http://doc.qt.nokia.com/4.7/qtimer.html#stop does not work?[/quote]

              I start it with:
              @
              QTimer::singleShot(360000, this, SLOT(mySlot()));
              @
              [/quote]

              If you change that to something like:

              @
              m_myLongTimer = new QTimer(this);
              m_myLongTimer->setInterval(360000);
              m_myLongTimer->setSingleShot(true);
              connect(m_myLongTimer, SIGNAL(timeout()), SLOT(myslot()));
              m_myLongTimer->start();
              @

              You can use this to stop again:
              @
              m_myLongTimer->stop();
              @

              Edit: added connect call to sample code

              1 Reply Last reply
              0
              • L Offline
                L Offline
                luca
                wrote on last edited by
                #7

                So it should be better to use a QTimer, set it with:
                @
                setSingleShot();
                @

                thanks.

                1 Reply Last reply
                0

                • Login

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