'QObject::QObject' cannot access private member declared in class 'QObject'

前端 未结 5 538
天命终不由人
天命终不由人 2020-12-15 17:44
class CHIProjectData : public QObject
{
public:
    CHIProjectData();
    CHIProjectData(QMap aProjectData,
                   CHIAkmMetaData*         


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-15 18:12

    The default constructor for QObject must be private and the error you are getting is quite likely to do with CHIProjectData::CHIProjectData (default constructor) implicitly trying to invoke base class's default constructor. If you look at QObject you would most likely find that it's defined something like this:

    class QObject {
        QObject(); //private contructor, derived classes cannot call this constructor
    public:
        QObject(QObject* aParent);
    };
    

    The solution is to make default QObject constructor protected or public or call other constructor overload from the default CHIProjectData constructor:

    CHIProjectData::CHIProjectData() : QObject(NULL){
    }
    

提交回复
热议问题