OR other way to formulate my question (though it didn’t solve my problem): 'QObject::QObject' cannot access private member declared in class 'QObject'
I need SIGNALs and SLOTS functionality in my class, but I assume it is not possible without to derive from QObject?
class MyClass
{
signals:
importantSignal();
public slots:
importantSlot();
};
The Problem seems to be that I need to derive from QObject to use signals and slots … but I need the default contructor of MyClass. But I can’t construct them because of the following feature of QObject:
No Copy Constructor or Assignment Operator.
I tried a lot …
So my shoul Class look like that:
#include <QObject>
class MyClass: public QObject
{
Q_OBJECT
public:
explicit MyClass(QObject *parent = 0); //autogenerated by qtcreator for QObject derived class
MyClass(const MyClass * other);
signals:
importantSignal();
public slots:
importantSlot();
};
I need the default contructor of MyClass.
So is there any possibility do avoid the “‘QObject::QObject’ cannot access private member declared in class ‘QObject'” error?
Or as an alternative is there any possibility to use signals and slots without QObject?
I’m glad for any advice.
If you want a copyable object with
QObjectfeatures you need membership (by pointer) rather than inheritence.You can derive a class
HandlerfromQObjectwhereHandler‘s slots callSomeInterfacevirtual functions on its parent.