还有其他的方式来表达我的问题(虽然它没有解决我的问题):'QObject::QObject' cannot access private member declared in class 'QObject'
我需要在我的类中使用SIGNALs和SLOTS功能,但我认为如果不从QObject
派生是不可能实现的?
class MyClass
{
signals:
importantSignal();
public slots:
importantSlot();
};
问题似乎是我需要继承自QObject来使用信号和槽,但我需要MyClass的默认构造函数。但由于QObject的以下特性,我无法构建它们: 没有复制构造函数或赋值运算符。我尝试了很多方法...
所以我的shoul类应该像这样:
#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();
};
我需要MyClass
的默认构造函数。
那么有没有可能避免 "'QObject:: QObject' 无法访问在类 'QObject' 中声明的私有成员" 错误?
或者,有没有可能在没有使用QObject
的情况下使用信号和槽?
我很高兴听取任何建议。