使用转换后的参数值连接信号和槽的任何简单方法。例如,我有一个signal(bool state)
,它连接到一个插槽slot(bool reversed_state)
,这里的状态是信号状态的反转状态(逻辑上不是)。
问问题
1762 次
1 回答
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);
于 2013-10-01T15:58:37.437 回答