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. Delay in QtWidget
QtWS25 Last Chance

Delay in QtWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 996 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.
  • K Offline
    K Offline
    KunalShah_4
    wrote on last edited by
    #1

    Hi i am trying to write a simple code for drawPoint , but not able to get the delay. Here is simple code which i have written.

    include two header files
    #include<QTime>
    #include<QCoreApplication>

    void Mainwindow::delay(double sec)
    {
    QTime dieTime= QTime::currentTime().addSecs(sec);
    while (QTime::currentTime() < dieTime)
    QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
    }

    calling delay using : delay(n) //n is seconds..

    Not able to get delay..

    1 Reply Last reply
    0
    • gfxxG Offline
      gfxxG Offline
      gfxx
      wrote on last edited by
      #2

      hi,

      QTimer::singleShot(100, [=]{ foo(); });
      

      is a possible solution ... but if your intent is to refresh sreen every 100ms I think the better use is QThread with :

      this->msleep(100);
      

      at the end of loop in Run call....

      regards
      giorgio

      bkt

      1 Reply Last reply
      0
      • K Offline
        K Offline
        KunalShah_4
        wrote on last edited by
        #3

        Thank for the reply..

        I want to create simple animation in Qt for my students. I have used this->msleep(100); , but I am geeting error"Program has terminated unexpectedly".

        I just want draw a point in for loop with some delay in order to show animation.

        jsulmJ 1 Reply Last reply
        0
        • K KunalShah_4

          Thank for the reply..

          I want to create simple animation in Qt for my students. I have used this->msleep(100); , but I am geeting error"Program has terminated unexpectedly".

          I just want draw a point in for loop with some delay in order to show animation.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @KunalShah_4 You should take a look at http://doc.qt.io/qt-5/animation.html

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

          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