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