简体   繁体   中英

How to update the GUI at a pre-determined interval, while still doing non-GUI work?

Basically, I'm doing some image processing and using a QImage in a QLabel to display the current frame in a video sequence. Let's say I want to update the QImage to the next frame at 30 fps (or if some processing is not done by the 30 fps interval, wait until it's done), but I don't want the whole program to stop during that 30 fps.

So the flow is...

if (done_some_work && 30fps_interval_has_passed)
{
   updateQImage();
}

How is this done in Qt? Thanks!

And use a QTimer to send a signal repaint the frame every 1000/30 ms

myTimer= new QTimer(this);
myTimer->setInterval(1000/fps); // ms
connect(myTimer, SIGNAL(timeout()), this, SLOT(doNextFrame())); 

// where
public slots:
    virtual void doNextFrame() {repaint();}

The comment is correct, you should do your work in another thread and then signal that you want to update the UI thread when you want to update something visually. Don't do processing work on the UI thread or your GUI will be unresponsive. This isn't so much a QT question as more of a GUI question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM