I want to have two different interface classes that declare signals and pure virtual slots, and have a implementation class that implements both of them and thus inherits their individual signals and slots. Something like this:
#include <QObject>
class Interface1
{
public:
virtual ~Interface1(){}
signals:
virtual void somethingHappened1() = 0;
public slots:
virtual void doSomething1() = 0;
}
class Interface2
{
public:
virtual ~Interface2(){}
signals:
virtual void somethingHappened2() = 0;
public slots:
virtual void doSomething2() = 0;
}
Then write the implementation like this:
class Implementation : public QObject, public Interface1, public Interface2
{
Q_OBJECT
signals:
void somethingHappened1() override;
void somethingHappened2() override;
public slots:
void doSomething1() override
{
// implementation goes here
}
void doSomething2() override
{
// implementation goes here
}
}
However, this only works in Qt 5. in Qt 6, and in my case Qt 6.6.2 onward, writing this gives a warning in the interface classes saying that I cannot have virtual signals in my code and an error message in interface classes saying that “classes that declare signals and slots must have the Q_OBJECT macro”
Which upon doing as it says, leads to another error message saying that if I include Q_OBJECT macro in the interface class then it should also inherit from QObject otherwise it doesn’t work.
Which then upon doing as it says, leads to the diamond inheritance error message for QObject!
So, is this feature removed in Qt 6 or am I missing something?
How can we have interfaces that define signals and slots and then implement them in Qt?