使用已转换的参数值连接信号和插槽的任何简单方法。例如,我有一个signal(bool state)
,它连接到一个插槽slot(bool reversed_state)
,这里状态是信号状态的反转状态(逻辑上不是)。
答案 0 :(得分:1)
创建一个中间插槽来链接两者: -
class MyClass : public QObject
{
Q_OBJECT
public:
signals:
void SomeSignal(bool state);
void SomeSignalSwitched(bool state); // reverse the state
public slots:
void ReversedStateSlot(bool reversed_state);
};
void MyClass::SomeSignalSwitched(bool state)
{
bool newState = !state
emit SomeSignalSwitched(newState);
}
// NOTE Qt 5 connect functions
connect(myClassObject, &MyClass::SomeSignal, myClassObject, &MyClass::SomeSignalSwitched);
connect(myClassObject, &MyClass::SomeSignalSwitched, myClassObject, &MyClass::ReversedStateSlot);