Connect QT signals declared in the interface

Is there a way to use a Qt5-style signal-to-slot connection if the signals are declared in the interfaces ?.

My interfaces:

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

signals:
    virtual void notify_signal() =0;
};
Q_DECLARE_INTERFACE(IMyInterfaces, "IMyInterfaces");

And the class that implements the interfaces above:

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

signals:
     void notify_signal();
};

In the main program, I would like to do something like this:

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

The old style works, but requires dropping in a QObject:

QObject::connect(dynamic_cast<QObject *>(m),SIGNAL(notify_signal()),other,SLOT(aSlot())); //This works but need to cast to QObject. 
+4
source share
1 answer

Signals cannot be virtual. It can be declared in interfaces without a virtual clause and must be inherited by lower classes.

0
source

Source: https://habr.com/ru/post/1609714/


All Articles