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 singleshot not working

Qtimer singleshot not working

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 4 Posters 1.3k 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.
  • I Offline
    I Offline
    IknowQT
    wrote on 7 Dec 2021, 08:59 last edited by
    #1
    wBIT w;
    w.setGeometry(0, 0, defineSize.width(), defineSize.height());
    w.show();
    QTimer::singleShot(1500, &w, SLOT(w.StopTest(false)));
    
    void wBIT::StopTest(bool bStop)
    {
       this->ui.wBitItem_Device->ProcessCheck(bStop);
       this->ui.wBitItem_WMotor->ProcessCheck(bStop);
       this->ui.wBitItem_CMotor->ProcessCheck(bStop);
       this->ui.wBitItem_FMotor->ProcessCheck(bStop);
       this->ui.wBitItem_LMotor->ProcessCheck(bStop);
       this->ui.wBitItem_TLamp	->ProcessCheck(bStop);
       this->ui.wBitItem_DLamp	->ProcessCheck(bStop);
       this->ui.wBitItem_DPeak	->ProcessCheck(bStop);
    }
    
    

    I want to send a stop signal after 1,500 milliseconds, but it doesn't work.

    J J 2 Replies Last reply 7 Dec 2021, 09:00
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 7 Dec 2021, 09:01 last edited by
      #3

      @IknowQT said in Qtimer singleshot not working:

      SLOT(w.StopTest(false)));

      This is wrong and you will also get a runtime warning on your console about this. If you want to pass a variable use the new signal/slot syntax with a lambda or call another slot which then calls the real function with your parameter.

      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
      3
      • I IknowQT
        7 Dec 2021, 08:59
        wBIT w;
        w.setGeometry(0, 0, defineSize.width(), defineSize.height());
        w.show();
        QTimer::singleShot(1500, &w, SLOT(w.StopTest(false)));
        
        void wBIT::StopTest(bool bStop)
        {
           this->ui.wBitItem_Device->ProcessCheck(bStop);
           this->ui.wBitItem_WMotor->ProcessCheck(bStop);
           this->ui.wBitItem_CMotor->ProcessCheck(bStop);
           this->ui.wBitItem_FMotor->ProcessCheck(bStop);
           this->ui.wBitItem_LMotor->ProcessCheck(bStop);
           this->ui.wBitItem_TLamp	->ProcessCheck(bStop);
           this->ui.wBitItem_DLamp	->ProcessCheck(bStop);
           this->ui.wBitItem_DPeak	->ProcessCheck(bStop);
        }
        
        

        I want to send a stop signal after 1,500 milliseconds, but it doesn't work.

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 7 Dec 2021, 09:00 last edited by
        #2

        @IknowQT said in Qtimer singleshot not working:

        wBIT w;

        This again...
        You are declaring a local variable, which gets out of scope and is deleted.
        Either allocate it on the heap or make it class member...

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

        1 Reply Last reply
        2
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 7 Dec 2021, 09:01 last edited by
          #3

          @IknowQT said in Qtimer singleshot not working:

          SLOT(w.StopTest(false)));

          This is wrong and you will also get a runtime warning on your console about this. If you want to pass a variable use the new signal/slot syntax with a lambda or call another slot which then calls the real function with your parameter.

          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
          3
          • I IknowQT
            7 Dec 2021, 08:59
            wBIT w;
            w.setGeometry(0, 0, defineSize.width(), defineSize.height());
            w.show();
            QTimer::singleShot(1500, &w, SLOT(w.StopTest(false)));
            
            void wBIT::StopTest(bool bStop)
            {
               this->ui.wBitItem_Device->ProcessCheck(bStop);
               this->ui.wBitItem_WMotor->ProcessCheck(bStop);
               this->ui.wBitItem_CMotor->ProcessCheck(bStop);
               this->ui.wBitItem_FMotor->ProcessCheck(bStop);
               this->ui.wBitItem_LMotor->ProcessCheck(bStop);
               this->ui.wBitItem_TLamp	->ProcessCheck(bStop);
               this->ui.wBitItem_DLamp	->ProcessCheck(bStop);
               this->ui.wBitItem_DPeak	->ProcessCheck(bStop);
            }
            
            

            I want to send a stop signal after 1,500 milliseconds, but it doesn't work.

            J Offline
            J Offline
            J.Hilk
            Moderators
            wrote on 7 Dec 2021, 09:01 last edited by
            #4

            @IknowQT said in Qtimer singleshot not working:

            SLOT(w.StopTest(false))

            this

            SLOT(w.StopTest(false))
            

            is 100% wrong, you can't set arguments in SLOT macro


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            2

            3/4

            7 Dec 2021, 09:01

            • Login

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