mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +08:00
Ref T786, singleShot for CSlot
This commit is contained in:
committed by
Mat Sutcliffe
parent
388138203e
commit
0fa6a6e4c3
@@ -11,14 +11,17 @@
|
||||
#ifndef BLACKMISC_SLOT_H
|
||||
#define BLACKMISC_SLOT_H
|
||||
|
||||
#include "blackmisc/invoke.h"
|
||||
|
||||
#include <QPointer>
|
||||
#include <QObject>
|
||||
#include <QtGlobal>
|
||||
#include <QTimer>
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include "blackmisc/invoke.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -100,6 +103,19 @@ namespace BlackMisc
|
||||
return m_function(args...);
|
||||
}
|
||||
|
||||
//! Call function "de-coupled" in original thread
|
||||
bool singleShot(Args... args) const
|
||||
{
|
||||
// does NOT return the values of m_function!
|
||||
if (!m_object || !m_function) { return false; }
|
||||
QTimer::singleShot(0, m_object.data(), [ = ]
|
||||
{
|
||||
if (!m_object || !m_function) { return; }
|
||||
m_function(args...);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
//! Returns the object which the slot belongs to.
|
||||
//! Use this as the third argument to QObject::connect to ensure the slot is called in the correct thread.
|
||||
QObject *object() const
|
||||
|
||||
Reference in New Issue
Block a user