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. Have "Sleep()" on the bottom of the QTimer, cant exit app instantly.
Forum Update on Monday, May 27th 2025

Have "Sleep()" on the bottom of the QTimer, cant exit app instantly.

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 314 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.
  • B Offline
    B Offline
    BD9a
    wrote on last edited by
    #1

    Hello, I cant exit app instantly when have Sleep on the bottom of QTimer function. It closing after sleep finished.

    void digging::startLoop()
    {
        check->start(1000); // Connected to "void digging::loop()"
        shutdown->start(200); // Connected to "void digging::wylacznik()"
    }
    
    void digging::wylacznik()
    {
        qDebug() << "off";
        if(GetAsyncKeyState(0x78)){
            leftUp();
            abort();
        }
    }
    
    
    void digging::loop()
    {
        qDebug() << "looped";
        if(GetAsyncKeyState(0x77)){
            enabled = true;
        }
        if(GetAsyncKeyState(0x78)){
            leftUp();
            abort();
        }
        if(enabled){
            if(!resized){
                qDebug() << "resized";
                resize();
                resized = true;
            }
    
            sendCommand("/naprawkilof");
            Sleep(500);
            leftDown();
            Sleep(5000); // I want to wait a bit before start loop again, and be ready to exit app in random moment.
        }
    }
    

    And what's the diffrence between QTimer start(x) and QTimer setInterval(x)?

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

      Hi,

      setInterval just sets the interval while start starts the timer with the given interval.

      As for your use of sleep, it will block the event loop hence it can't process normally.

      If you want to introduce different delays you should reconsider your design. Maybe use a state machine.

      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
      3

      • Login

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