我需要根据参数类型从 SomeClass::fireSignal 成员函数中触发不同的信号。我看到的解决方案是使用 Qt 元系统。这样的任务有更正确的解决方案吗?请帮忙。提前致谢。
class SomeClass : public QObject
{
Q_OBJECT
public:
void fireSignal(BaseClass *param) {
if(param->metaObject->className() == "DerivedClass1") {
emit derivedClass1Signal(param)
}
if(param->metaObject->className() == "SecondDerivedClass") {
emit secondDerivedClassSignal(param)
}
if(param->metaObject->className() == "OtherDerivedClass") {
emit otherDerivedClassSignal(param)
}
}
signals:
void derivedClass1Signal(DerivedClass1 *param);
void secondDerivedClassSignal(SecondDerivedClass *param);
void otherDerivedClassSignal(OtherDerivedClass *param)
};