您可以使用 SIGNAL/SIGNAL 连接来转发具有兼容签名的信号。在下面的代码示例中,重要的部分是 LogicClass1 的构造函数中的连接。
// My other logic class
class LogicClass1 : public QObject
{ Q_OBJECT
public:
LogicClass1(LogicClass2* lc2)
: lc2(lc2)
{
connect(lc2, SIGNAL(signalPrograssIteration(int)),
this, SIGNAL(signalPrograssIteration(int)));
}
signals:
void signalPrograssIteration(int);
private:
LogicClass2 *lc2;
};
// My other logic class
class LogicClass2 : public QObject
{ Q_OBJECT
public:
LogicClass2(){}
signals:
void signalPrograssIteration(int);
private:
void doSomething();
};
// the function that actually does stuff
void LogicClass2::doSomthing()
{
int val = 0;
for(...)
{
.
.
emit signalPrograssIteration(val);
.
.
}
}
您可以在QObject::connect的文档中看到类似的示例。