连接接口中声明的QT信号

sng*_*sng 6 c++ qt interface signals-slots

如果在接口中声明信号,有没有办法使用Qt5样式的信号和插槽连接?

我的界面:

class IMyInterfaces{
protected:
    IMyInterfaces() {} //Prohibit instantiate interfaces
public:
    virtual ~IMyInterfaces(){} 

signals:
    virtual void notify_signal() =0;
};
Q_DECLARE_INTERFACE(IMyInterfaces, "IMyInterfaces");
Run Code Online (Sandbox Code Playgroud)

以及实现上述接口的类:

class MyClass : public QObject, public IMyInterfaces{
    Q_OBJECT
    Q_INTERFACES(IMyInterfaces) //Indicates interface implements
public:
    MyClass():QObject(){
    }
    ~MyClass(){}

signals:
     void notify_signal();
};
Run Code Online (Sandbox Code Playgroud)

在主程序中,我想做这样的事情:

IMyInterfaces * myObject = new MyClass();
//Connect signal using Qt5 style (This will introduce compilation errors)
connect(myObject ,&IMyInterfaces::notify_signal, otherObject, &OtherClass::aSlot);
Run Code Online (Sandbox Code Playgroud)

旧样式有效,但需要强制转换为QObject:

QObject::connect(dynamic_cast<QObject *>(m),SIGNAL(notify_signal()),other,SLOT(aSlot())); //This works but need to cast to QObject. 
Run Code Online (Sandbox Code Playgroud)

Aur*_*anu 0

信号不可能是虚拟的。可以在没有 virtual 子句的接口中声明,并且应该由较低的类继承。