Reputation: 33579
Is there a wrapper function for Sleep
/ usleep
in Qt that can be used in the main thread, or do I have to write my own wrapper? It's not a lot of code, but would be a shame to write my own if there already is one.
Upvotes: 1
Views: 142
Reputation: 13984
Variant 1:
Pro-file:
CONFIG += qtestlib
Code:
#include <QTest>
QTest::qSleep( 10000 ); // 10 sec
Variant 2:
#ifndef XSLEEP_H
#define XSLEEP_H
#include <QThread>
class Xsleep : public QThread
{
public:
static void msleep(int ms)
{
QThread::msleep(ms);
}
};
#endif
C++:
while (true)
{
...
Xsleep::msleep(1000); // 1 sek
...
}
Upvotes: 2