Delay in QtWidget



  • 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..



  • 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



  • 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.


  • Moderators


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.