cosmos
17th October 2017, 17:59
hello, suppose i hava class A and B with signal123 and slot123,
I want to connect the A's signals to B's slots in just one function, because it is often used, and it is boring to write 3 connects.
my program wont compile.
is there a correct way to do this?
thank you.
example class A and B:
class A : public QObject
{
Q_OBJECT
public:
explicit A(QObject *parent = nullptr):QObject(parent){}
template<typename slot1, typename slot2, typename slot3>
void setSlot(QObject *recv, slot1 f1, slot2 f2, slot3 f3) {
connect(this,&A::signal1,recv,f1);
connect(this,&A::signal2,recv,f2);
connect(this,&A::signal3,recv,f3);
}
signals:
void signal1();
void signal2();
void signal3();
};
class B : public QObject
{
Q_OBJECT
public:
explicit B(QObject *parent = nullptr):QObject(parent){}
public slots:
void slot1() {printf("slot1");}
void slot2() {printf("slot2");}
void slot3() {printf("slot3");}
};
I want to connect the A's signals to B's slots in just one function, because it is often used, and it is boring to write 3 connects.
my program wont compile.
is there a correct way to do this?
thank you.
example class A and B:
class A : public QObject
{
Q_OBJECT
public:
explicit A(QObject *parent = nullptr):QObject(parent){}
template<typename slot1, typename slot2, typename slot3>
void setSlot(QObject *recv, slot1 f1, slot2 f2, slot3 f3) {
connect(this,&A::signal1,recv,f1);
connect(this,&A::signal2,recv,f2);
connect(this,&A::signal3,recv,f3);
}
signals:
void signal1();
void signal2();
void signal3();
};
class B : public QObject
{
Q_OBJECT
public:
explicit B(QObject *parent = nullptr):QObject(parent){}
public slots:
void slot1() {printf("slot1");}
void slot2() {printf("slot2");}
void slot3() {printf("slot3");}
};