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
Qt 6.11 is out! See what's new in the release blog

Qtimer singleshot not working

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 4 Posters 1.9k 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 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.

    jsulmJ J.HilkJ 2 Replies Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 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
        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.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on 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
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 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
            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.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on 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

            • Login

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