PIQCONNECT, QPICONNECT and PIQCONNECT_QUEUED now automatic disconnects on target object delete
PIQCONNECT[_QUEUED] now returns PIObject::Connection
This commit is contained in:
@@ -61,27 +61,36 @@ QArgument<T> qargument(const T & v) {
|
||||
}
|
||||
|
||||
template<typename SR, typename O, typename... ARGS>
|
||||
void piqConnect(PIObject * source, const char * event, void (*func)(void *, ARGS...), O * target, SR (O::*slot)(ARGS...)) {
|
||||
PIObject::piConnectLS(source,
|
||||
PIStringAscii(event),
|
||||
PIObject::__newFunctor(func, [target, slot](ARGS... args) { (target->*slot)(args...); }),
|
||||
LOCATION);
|
||||
PIObject::Connection piqConnect(PIObject * source, const char * event, void (*func)(void *, ARGS...), O * target, SR (O::*slot)(ARGS...)) {
|
||||
PIObject::Connection ret =
|
||||
PIObject::piConnectLS(source,
|
||||
PIStringAscii(event),
|
||||
PIObject::__newFunctor(func, [target, slot](ARGS... args) { (target->*slot)(args...); }),
|
||||
LOCATION);
|
||||
QObject::connect(target, &QObject::destroyed, [ret]() { ret.disconnect(); });
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename... ARGS>
|
||||
void piqConnectQ(PIObject * source, const char * event, void (*func)(void *, ARGS...), QObject * target, const char * slot) {
|
||||
PIObject::piConnectLS(source,
|
||||
PIStringAscii(event),
|
||||
PIObject::__newFunctor(func,
|
||||
[target, slot](ARGS... args) {
|
||||
QMetaObject::invokeMethod(target, slot, Qt::QueuedConnection, qargument(args)...);
|
||||
}),
|
||||
LOCATION);
|
||||
PIObject::Connection
|
||||
piqConnectQ(PIObject * source, const char * event, void (*func)(void *, ARGS...), QObject * target, const char * slot) {
|
||||
PIObject::Connection ret =
|
||||
PIObject::piConnectLS(source,
|
||||
PIStringAscii(event),
|
||||
PIObject::__newFunctor(func,
|
||||
[target, slot](ARGS... args) {
|
||||
QMetaObject::invokeMethod(target, slot, Qt::QueuedConnection, qargument(args)...);
|
||||
}),
|
||||
LOCATION);
|
||||
QObject::connect(target, &QObject::destroyed, [ret]() { ret.disconnect(); });
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename SR, typename O, typename... ARGS>
|
||||
QMetaObject::Connection qpiConnect(O * source, SR (O::*signal)(ARGS...), PIObject * target, void (*handler)(void *, ARGS...)) {
|
||||
return QObject::connect(source, signal, source, [target, handler](ARGS... args) { handler(target, args...); });
|
||||
auto ret = QObject::connect(source, signal, source, [target, handler](ARGS... args) { handler(target, args...); });
|
||||
CONNECTL(target, deleted, [ret](PIObject *) { QObject::disconnect(ret); });
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace PIQt
|
||||
|
||||
Reference in New Issue
Block a user