#ifndef UTILS_H
#define UTILS_H
#include <QCoreApplication>
#include <QElapsedTimer>
namespace Utils
{
inline static void qSleep(int ms)
{
Q_ASSERT(ms > 0);
#ifdef Q_OS_WIN
Sleep(uint(ms));
#else
struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 };
nanosleep(&ts, NULL);
#endif
}
inline static void qWait(int ms)
{
Q_ASSERT(QCoreApplication::instance());
QElapsedTimer timer;
timer.start();
do {
QCoreApplication::processEvents(QEventLoop::AllEvents, ms);
Utils::qSleep(10);
} while (timer.elapsed() < ms);
}
}
#endif // UTILS_H