I would like to have a proxy for QObject::connect in a base class. The goal is to store all the QMetaObject::Connection returned by connect in a vector.
class MyBaseClass : public QObject {
Q_OBJECT;
template <typename... Args>
void addConnection(Args... args) {
auto c = this->connect(args...);
if (c) {
connections.push_back(c);
}
}
The issue is that the connection does not work anymore. When I emit a signal from a class that inherits MyBaseClass, it does nothing. For example, this does work :
connect(this, &ClassThatInheritsBaseClass::valueChanged, [this](int v) {
qDebug() << QString::number(value);
}
But this does not work :
addConnection(this, &ClassThatInheritsBaseClass::valueChanged, [this](int v) {
qDebug() << QString::number(value);
}
Could someone explain me why it does not work ? And how to make it work ?
Aucun commentaire:
Enregistrer un commentaire