[Qt-interest] Nested Custom Types

Samuel Gaist samuel.gaist at edeltech.ch
Fri Apr 1 17:20:31 CEST 2011


Hi,

The simple and short answer is: QObject cannot be copied

For more information :
http://doc.qt.nokia.com/4.7/qobject.html#details

Hope this helps
Samuel

On 1 avr. 2011, at 17:07, Thomas Ehrnhoefer wrote:

> Hi
> 
> I am new to Qt and am currently in the process of working on the model of my application. Since I want to take advantage of the MetaObjectModel (need to generically (un)marshall data to objects), I am studying and using the documentation available on this.
> However I am running into compiler issues with nested custom types (see end of email for sample code).
> 
> The error I am getting is when compiling the custom type which has another custom type as member, and the output is something like:
> 
> [some].h(34) : error C2248: 'QObject::operator =' : cannot access private member declared in class 'QObject'
> This diagnostic occurred in the compiler generated function '[some] &[some]::operator =(const [some] &)'
> 
> Any input would be very much appreciated, thanks!
> 
> Thomas
> 
> P.S.:
> Here is a simple example of what me code looks like. There is a simple Person object, and a Container object with a person as member:
> 
> ===== person.h =====
> #ifndef PERSON_H
> #define PERSON_H
> #include <QObject>
> #include <QMetaType>
> 
> class Person : public QObject
> {
>     Q_OBJECT
>     Q_PROPERTY(QString _name READ name WRITE setName)
> 
> public:
>     Person();
>     Person(const Person &other);
>     Person(QObject *parent);
>     ~Person();
> public slots:
>     QString name() const;
>     void setName(QString name);
> private:
>     QString _name;
> };
> Q_DECLARE_METATYPE(Person);
> #endif // PERSON_H
> 
> 
> 
> ===== person.cpp =====
> #include "person.h"
> 
> Person::Person() {}
> 
> Person::Person(const Person &other) { _name = other._name; }
> 
> Person::Person(QObject *parent) : QObject(parent){}
> 
> Person::~Person(){}
> 
> QString Person::name() const { return _name; }
> 
> void Person::setName(QString name) { _name = name; }
> 
> 
> 
> ===== container.h =====
> #ifndef CONTAINER_H
> #define CONTAINER_H
> #include <QObject>
> #include <QMetaType>
> 
> class Container : public QObject
> {
>     Q_OBJECT
>     Q_PROPERTY(QString _summary READ summary WRITE setSummary)
>     Q_PROPERTY(Person _owner READ owner WRITE setOwner)
> public:
>     Container();
>     Container(const Container &other);
>     Container(QObject *parent);
>     ~Container();
> public slots:
>     QString summary() const;
>     Person owner() const;
>     void setOwner(Person owner);
>     void setSummary(QString summary);
> private:
>     QString _summary;
>     Person _owner;
> };
> 
> Q_DECLARE_METATYPE(Container);
> #endif // CONTAINER_H
> 
> 
> 
> ===== container.cpp =====
> 
> #include "container.h"
> 
> Container::Container()
> {
> }
> 
> Container::Container(const Container &other) :
>     _owner(other._owner())
> {
>     _summary = other._summary;
> }
> 
> Container::Container(QObject *parent) : QObject(parent) {}
> 
> Container::~Container() {}
> 
> QString Container::summary() const { return _summary; }
> 
> Person TaskHandle::owner() const { return _owner; }
> 
> void Container::setSummary(QString summary) { _summary = summary; }
> 
> void TaskHandle::setOwner(Person owner) { _owner = owner; }
> 
> 
> 
> -- 
> Thomas Ehrnhoefer
> Software Developer, http://tasktop.com
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest




More information about the Qt-interest-old mailing list