DAWorkbench
0.0.1
DAWorkbench API
载入中...
搜索中...
未找到
DAPythonSignalHandler.h
1
#ifndef DAPYTHONSIGNALHANDLER_H
2
#define DAPYTHONSIGNALHANDLER_H
3
#include <QObject>
4
#include <QMap>
5
#include <DAPyBindQtGlobal.h>
6
#include <functional>
7
#include <memory>
8
#include <mutex>
9
#include "DAPyBindQtGlobal.h"
10
namespace
DA
11
{
18
class
DAPYBINDQT_API
DAPythonSignalHandler
:
public
QObject
19
{
20
Q_OBJECT
21
22
public
:
23
explicit
DAPythonSignalHandler
(QObject* parent =
nullptr
);
24
virtual
~DAPythonSignalHandler
();
25
26
// 删除拷贝构造和赋值操作符
27
DAPythonSignalHandler
(
const
DAPythonSignalHandler
&) =
delete
;
28
DAPythonSignalHandler
& operator=(
const
DAPythonSignalHandler
&) =
delete
;
29
36
void
callInMainThread(std::function<
void
() > func);
37
43
void
clearPendingFunctions();
44
45
Q_SIGNALS:
50
void
executeRequested
(
int
funcWrapperId);
51
52
private
Q_SLOTS:
57
void
onExecuteRequested(
int
funcWrapperId);
58
59
public
:
60
// 函数包装器,用于存储待执行的函数
61
class
FunctionWrapper
62
{
63
public
:
64
explicit
FunctionWrapper
(std::function<
void
() > func) : m_func(func)
65
{
66
}
67
void
execute()
68
{
69
if
(m_func)
70
m_func();
71
}
72
73
private
:
74
std::function< void() > m_func;
75
};
76
77
// 使用智能指针管理函数包装器
78
using
FunctionWrapperPtr = std::shared_ptr< FunctionWrapper >;
79
80
private
:
81
// 存储函数包装器的映射,键是唯一ID
82
QMap< int, FunctionWrapperPtr > m_functionMap;
83
84
// 线程安全保护
85
std::mutex m_mutex;
86
87
// 下一个函数包装器的ID
88
int
m_nextFuncId { 0 };
89
90
// 是否正在销毁中
91
bool
m_destroying {
false
};
92
};
93
}
// end DA
94
#endif
// DAPYTHONSIGNALHANDLER_H
DA::DAPythonSignalHandler::FunctionWrapper
Definition
DAPythonSignalHandler.h:62
DA::DAPythonSignalHandler
Python线程到Qt主线程的通信处理器
Definition
DAPythonSignalHandler.h:19
DA::DAPythonSignalHandler::executeRequested
void executeRequested(int funcWrapperId)
内部信号,用于触发主线程执行
DA
序列化类都是带异常的,使用中需要处理异常
Definition
AppMainWindow.cpp:44
src
DAPyBindQt
DAPythonSignalHandler.h
制作者
1.9.8