2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2016-01-15 14:55:33 +01:00
|
|
|
|
2016-09-15 17:41:41 +02:00
|
|
|
#include "processevents-utilities.h"
|
2015-11-25 15:21:24 +01:00
|
|
|
|
2016-05-31 16:07:09 +02:00
|
|
|
#include <QCoreApplication>
|
2019-08-19 12:35:35 +02:00
|
|
|
#include <QElapsedTimer>
|
2016-05-31 16:07:09 +02:00
|
|
|
#include <QThread>
|
2015-11-25 15:21:24 +01:00
|
|
|
|
2016-05-31 16:07:09 +02:00
|
|
|
#include <QDebug>
|
|
|
|
|
|
2016-09-15 17:41:41 +02:00
|
|
|
namespace ProcessEventUtilities
|
|
|
|
|
{
|
|
|
|
|
bool processEventsUntilTrue(std::function<bool ()> condition, int timeOutInMs)
|
2015-11-25 15:21:24 +01:00
|
|
|
{
|
2016-05-31 16:07:09 +02:00
|
|
|
if (condition())
|
|
|
|
|
return true;
|
2015-11-25 15:21:24 +01:00
|
|
|
|
2019-08-19 12:35:35 +02:00
|
|
|
QElapsedTimer time;
|
2016-05-31 16:07:09 +02:00
|
|
|
time.start();
|
2015-11-25 15:21:24 +01:00
|
|
|
|
2016-05-31 16:07:09 +02:00
|
|
|
forever {
|
|
|
|
|
if (condition())
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (time.elapsed() > timeOutInMs) {
|
|
|
|
|
qWarning() << "Timeout of" << timeOutInMs
|
|
|
|
|
<< "reached in processEventsAndWaitUntilTrue()";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-15 17:41:41 +02:00
|
|
|
}
|