What is the best way to exit out of a loop after an elapsed time of 30ms in C++

后端 未结 9 1001
感动是毒
感动是毒 2020-12-11 13:24

What is the best way to exit out of a loop as close to 30ms as possible in C++. Polling boost:microsec_clock ? Polling QTime ? Something else?

Something like:

9条回答
  •  抹茶落季
    2020-12-11 14:04

    If you are using Qt, here is a simple way to do this:

    QTimer* t = new QTimer( parent ) ;
    t->setInterval( 30 ) ; // in msec
    t->setSingleShot( false ) ;
    connect( t, SIGNAL( timeout() ), viewPort, SLOT( redraw() ) ) ;
    

    You'll need to specify viewPort and redraw(). Then start the timer with t->start().

提交回复
热议问题