Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
qt_helpers.h
1// SPDX-FileCopyrightText: © 2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <QEventLoop>
7#include <QFuture>
8#include <QFutureWatcher>
9#include <QTimer>
10
11namespace zrythm::test_helpers
12{
13
25template <typename T>
26bool
27waitForFutureWithEvents (QFuture<T> &future, int timeout_ms = 30000)
28{
29 if (future.isFinished ())
30 return true;
31
32 QFutureWatcher<T> watcher;
33 QEventLoop loop;
34 bool timed_out = false;
35
36 QObject::connect (
37 &watcher, &QFutureWatcher<T>::finished, &loop, [&loop, &timed_out] () {
38 timed_out = false;
39 loop.quit ();
40 });
41
42 watcher.setFuture (future);
43
44 // Timeout to prevent infinite hang
45 QTimer::singleShot (timeout_ms, &loop, [&loop, &timed_out] () {
46 timed_out = true;
47 loop.quit ();
48 });
49
50 loop.exec ();
51
52 return !timed_out && future.isFinished ();
53}
54
55} // namespace zrythm::test_helpers