mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 21:37:52 -07:00
QtUtils: add QueueOnObject
This commit is contained in:
parent
8292d378ea
commit
734c9e1459
20
Source/Core/DolphinQt2/QtUtils/QueueOnObject.h
Normal file
20
Source/Core/DolphinQt2/QtUtils/QueueOnObject.h
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright 2017 Dolphin Emulator Project
|
||||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <utility>
|
||||
|
||||
// QWidget and subclasses are not thread-safe! However, Qt's signal-slot connection mechanism will
|
||||
// invoke slots/functions on the correct thread for any object. We can (ab)use this to queue up
|
||||
// arbitrary code from non-GUI threads. For more information, see:
|
||||
// https://stackoverflow.com/questions/21646467/
|
||||
|
||||
template <typename F>
|
||||
static void QueueOnObject(QObject* obj, F&& func)
|
||||
{
|
||||
QObject src;
|
||||
QObject::connect(&src, &QObject::destroyed, obj, std::forward<F>(func), Qt::QueuedConnection);
|
||||
}
|
Loading…
Reference in New Issue
Block a user