Debian Codegraph @

Source/Core/DolphinQt/QtUtils/QueueOnObject.h

raw symbols SCIP
1 // Copyright 2017 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <QObject>
7 #include <utility>
8
9 // QWidget and subclasses are not thread-safe! However, Qt's signal-slot connection mechanism will
10 // invoke slots/functions on the correct thread for any object. We can (ab)use this to queue up
11 // arbitrary code from non-GUI threads. For more information, see:
12 // https://stackoverflow.com/questions/21646467/
13
14 template <typename T, typename F>
15 static void QueueOnObject(T* obj, F&& func)
16 {
17 QObject src;
18 QObject::connect(&src, &QObject::destroyed, obj, std::forward<F>(func), Qt::QueuedConnection);
19 }
20
21 template <typename T, typename F>
22 static void QueueOnObjectBlocking(T* obj, F&& func)
23 {
24 QObject src;
25 QObject::connect(&src, &QObject::destroyed, obj, std::forward<F>(func),
26 Qt::BlockingQueuedConnection);
27 }