Skip to content

Commit e321e6f

Browse files
authored
Don't use QTimer in dispatchToMain (#1237)
IB-7904 Signed-off-by: Raul Metsma <[email protected]>
1 parent 13f107a commit e321e6f

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

client/Application.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,7 @@ Application::Application( int &argc, char **argv )
444444
Q_EMIT qApp->TSLLoadingFinished();
445445
qApp->d->ready = true;
446446
if(ex) {
447-
dispatchToMain([ex] {
448-
showWarning(tr("Failed to initalize."), *ex);
449-
});
447+
dispatchToMain(showWarning, tr("Failed to initalize."), *ex);
450448
}
451449
}
452450
);

client/Utils.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,18 @@ namespace {
4949
template <typename F, class... Args>
5050
inline auto dispatchToMain(F&& function, Args&& ...args) {
5151
QEventLoop l;
52-
QTimer *timer = new QTimer();
53-
timer->moveToThread(qApp->thread());
54-
timer->setSingleShot(true);
5552
if constexpr (std::is_void_v<std::invoke_result_t<F,Args...>>) {
56-
QObject::connect(timer, &QTimer::timeout, timer, [&, function = std::forward<F>(function)] {
53+
QMetaObject::invokeMethod(qApp, [&, function = std::forward<F>(function)] {
5754
std::invoke(function, args...);
5855
l.exit();
59-
timer->deleteLater();
60-
});
61-
QMetaObject::invokeMethod(timer, [timer] { timer->start(0); }, Qt::QueuedConnection);
56+
}, Qt::QueuedConnection);
6257
l.exec();
6358
} else {
6459
std::invoke_result_t<F,Args...> result{};
65-
QObject::connect(timer, &QTimer::timeout, timer, [&, function = std::forward<F>(function)] {
60+
QMetaObject::invokeMethod(qApp, [&, function = std::forward<F>(function)] {
6661
result = std::invoke(function, args...);
6762
l.exit();
68-
timer->deleteLater();
69-
});
70-
QMetaObject::invokeMethod(timer, [timer] { timer->start(0); }, Qt::QueuedConnection);
63+
}, Qt::QueuedConnection);
7164
l.exec();
7265
return result;
7366
}

0 commit comments

Comments
 (0)