I have a class that would listen via connect to some signals in a couple of different contexts, and a dialog that would do said listening among other things.
class MyListener : public QObject
{
Q_OBJECT
};
class MyDialog : public QDialog, public MyListener
{
Q_OBJECT
};
That caused the following compilation error:
error: reference to 'connect' is ambiguous
I suspected that may be caused by multiple inheritance of QObject by MyDialog, once via QDialog and once via MyListener. However, making all the above inheritance statements virtual didn't eliminate the error.
Could you suggest what may be the cause of this?
Make it:
class MyDialog : public QDialog
{
Q_OBJECT
public:
MyListener& listener() { return m_listener; }
private:
MyListener m_listener;
};
Have you considered inheriting your QObject as protected instead? This is because both classes use the connect() function to connect slots and signals together in your .ui file, having each class inherit each other means you now have two possible connect functions whenever the program makes a call to connect your signal/slots
have your needed functions under protected and prevent the ambiguity of two connect()
class MyListener
{
public:
//...
protected:
int a;
//stuff to share
};
class MyDialog: public QDialog, protected MyListener
{
//has access to all protected members but not the private members
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With