Saturday, September 06, 2014

Solved: error: C2248: 'QObject::QObject' : cannot access private member declared in class 'QObject'

Added two classes A and B both inheriting QObject.

#include <QObject>
#include "b.h"

class A : public QObject
{
    Q_OBJECT
public:
    explicit A(QObject *parent = 0);

    QList<B> doStuff();

signals:

public slots:


};





#include <QObject>

class B : public QObject
{
    Q_OBJECT
public:
    explicit B(QObject *parent = 0);


signals:

public slots:

};

But when adding implementation for A:

QList<GUIContainer> A::doStuff()
{
    QList<B> list;
    return list;

}


The compiler started complaining:
error: C2248: 'QObject::QObject' : cannot access private member declared in class 'QObject'


It complains because:
"The values stored in the various containers can be of any assignable data type. To qualify, a type must provide a default constructor, a copy constructor, and an assignment operator."
http://qt-project.org/doc/qt-4.8/containers.html


Solved the error by changing the QList to be a list of QSharedPointer:
QList<QSharedPointer<B> > doStuff();


1 comment:

superiorpapers.com review said...

What amazes me most is the execution is realeased back to the event loop untill the async method is ececuted and comleted. Keep up with the great job of sharing this here.