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();


2 comments:

frankie 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.

gardinifill said...

How to bet on the Borgata in Atlantic City - Dr.MD
How to bet 공주 출장샵 on 의정부 출장마사지 the Borgata in Atlantic City: 평택 출장마사지 Directions How 제천 출장샵 to 안양 출장샵 bet on the Borgata in Atlantic City. Borgata has a very good team and an excellent team.