PDA

View Full Version : Problem with my object hierarchy



rage
10th October 2007, 09:10
I have a problem with my object hierarchy. I have child classes "Point", "LineString", ... which inherits the parent class "Geometry".
Now I want to emit signals from the child objects, so I added QObject to the parent class


class Geometry : public QObject
{
Q_OBJECT
public:
Geometry(QString name = QString());
...
}


On compiling I get the following error:



/usr/include/QtCore/qobject.h:287: error: 'QObject::QObject(const QObject&)' is private
src/geometry.h:31: error: within this context
src/point.h: In copy constructor 'Point::Point(const Point&)':
src/point.h:31: note: synthesized method 'Geometry::Geometry(const Geometry&)' first required here
/usr/include/QtCore/qlist.h: In member function 'void QList<T>::append(const T&) [with T = Point]':
/usr/include/QtCore/qlist.h:419: note: synthesized method 'Point::Point(const Point&)' first required here
/usr/include/QtCore/qobject.h: In member function 'Geometry& Geometry::operator=(const Geometry&)':
src/geometry.h:31: instantiated from 'void QList<T>::node_construct(QList<T>::Node*, const T&) [with T = Point]'
/usr/include/QtCore/qlist.h:417: instantiated from 'void QList<T>::append(const T&) [with T = Point]'
src/linestring.cpp:68: instantiated from here
/usr/include/QtCore/qobject.h:287: error: 'QObject& QObject::operator=(const QObject&)' is private
src/geometry.h:31: error: within this context
src/point.h: In member function 'Point& Point::operator=(const Point&)':
src/point.h:31: note: synthesized method 'Geometry& Geometry::operator=(const Geometry&)' first required here
/usr/include/QtCore/qlist.h: In member function 'void QList<T>::node_construct(QList<T>::Node*, const T&) [with T = Point]':
/usr/include/QtCore/qlist.h:332: note: synthesized method 'Point& Point::operator=(const Point&)' first required here
gmake: *** [linestring.o] Error 1
*** Exited with status: 2 ***

I've read, that the copy constructor of QObject is private though it's not possible to make copies from derived objects.
But the whole Qt object hierarchy does it the same QObject -> QFrame -> QAbstractScrollArea -> QTextEdit
Why does this work? Where is the problem with my code?

jpn
10th October 2007, 09:18
QList makes copies. You can't add QObjects to a QList but you can add pointers to QObjects.


QList<QObject> list1; // <-- not ok
QList<QObject*> list2; // <-- ok


PS. Copying objects and inheritance are different concepts.