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. QT Timer Timeout
Forum Updated to NodeBB v4.3 + New Features

QT Timer Timeout

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 446 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.
  • A Offline
    A Offline
    Ayush Gupta
    wrote on 24 Aug 2020, 05:58 last edited by
    #1

    I am trying to execute below code

    QTimer test;
    QObject::connect(test, SIGNAL(timeout()), this, SLOT(testSlot()));

    test->start(3000);

    I want that my slot should execute immediately after start then after 3000ms it should execute.
    But currently what is happening slot is executing after 3000ms.

    Is there any way to solve it ?

    J 1 Reply Last reply 24 Aug 2020, 06:02
    0
    • A Ayush Gupta
      24 Aug 2020, 05:58

      I am trying to execute below code

      QTimer test;
      QObject::connect(test, SIGNAL(timeout()), this, SLOT(testSlot()));

      test->start(3000);

      I want that my slot should execute immediately after start then after 3000ms it should execute.
      But currently what is happening slot is executing after 3000ms.

      Is there any way to solve it ?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 24 Aug 2020, 06:02 last edited by
      #2

      @Ayush-Gupta said in QT Timer Timeout:

      I want that my slot should execute immediately after start then after 3000ms it should execute.

      I don't understand this. Your code is doing exactly what you asked it to do: call slot after 3000ms timeout. So, what do you want to do? Do you want to execute it after test->start(3000); and then second time after 3000ms timeout? if so, why not simply:

      QTimer test;
      QObject::connect(test, SIGNAL(timeout()), this, SLOT(testSlot()));
      
      test->start(3000);
      testSlot();
      

      ?

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

      A 1 Reply Last reply 24 Aug 2020, 06:06
      1
      • J jsulm
        24 Aug 2020, 06:02

        @Ayush-Gupta said in QT Timer Timeout:

        I want that my slot should execute immediately after start then after 3000ms it should execute.

        I don't understand this. Your code is doing exactly what you asked it to do: call slot after 3000ms timeout. So, what do you want to do? Do you want to execute it after test->start(3000); and then second time after 3000ms timeout? if so, why not simply:

        QTimer test;
        QObject::connect(test, SIGNAL(timeout()), this, SLOT(testSlot()));
        
        test->start(3000);
        testSlot();
        

        ?

        A Offline
        A Offline
        Ayush Gupta
        wrote on 24 Aug 2020, 06:06 last edited by
        #3

        @jsulm Yes that is great idea.. It did not came to my mind. Thanks.

        1 Reply Last reply
        0

        1/3

        24 Aug 2020, 05:58

        • Login

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