[Qt-interest] efficient Wait for Thread finished?

Matthias Pospiech matthias.pospiech at gmx.de
Tue Jan 20 11:00:08 CET 2009


I have a QThread which saves my data. If my simulation is faster than 
the data was saved, I have to delay the simulation.

Currently that looks like the following:

#ifndef _DELAY_H
#define _DELAY_H
#include <QtCore/QTime>        
inline void delay(long ms)  //  Zeit im ms
{
        QTime time;
        time.start();
        while (time.elapsed()<ms);          
}
#endif

void SaveDataThread::reset()
{
    // only reset if not running anymore
    while (isRunning()) {
        delay(200);
    }
...
}

Is this method ok? Or is the delay comsumming CPU and therefore 
additionally blocking the Thread?
How should it look like?




More information about the Qt-interest-old mailing list