Results 1 to 2 of 2

Thread: Problem with my object hierarchy

  1. #1
    Join Date
    Sep 2007
    Location
    Berlin, Germany
    Posts
    17
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60

    Default Problem with my object hierarchy

    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
    Qt Code:
    1. class Geometry : public QObject
    2. {
    3. Q_OBJECT
    4. public:
    5. Geometry(QString name = QString());
    6. ...
    7. }
    To copy to clipboard, switch view to plain text mode 

    On compiling I get the following error:

    Qt Code:
    1. /usr/include/QtCore/qobject.h:287: error: 'QObject::QObject(const QObject&)' is private
    2. src/geometry.h:31: error: within this context
    3. src/point.h: In copy constructor 'Point::Point(const Point&)':
    4. src/point.h:31: note: synthesized method 'Geometry::Geometry(const Geometry&)' first required here
    5. /usr/include/QtCore/qlist.h: In member function 'void QList<T>::append(const T&) [with T = Point]':
    6. /usr/include/QtCore/qlist.h:419: note: synthesized method 'Point::Point(const Point&)' first required here
    7. /usr/include/QtCore/qobject.h: In member function 'Geometry& Geometry::operator=(const Geometry&)':
    8. src/geometry.h:31: instantiated from 'void QList<T>::node_construct(QList<T>::Node*, const T&) [with T = Point]'
    9. /usr/include/QtCore/qlist.h:417: instantiated from 'void QList<T>::append(const T&) [with T = Point]'
    10. src/linestring.cpp:68: instantiated from here
    11. /usr/include/QtCore/qobject.h:287: error: 'QObject& QObject::operator=(const QObject&)' is private
    12. src/geometry.h:31: error: within this context
    13. src/point.h: In member function 'Point& Point::operator=(const Point&)':
    14. src/point.h:31: note: synthesized method 'Geometry& Geometry::operator=(const Geometry&)' first required here
    15. /usr/include/QtCore/qlist.h: In member function 'void QList<T>::node_construct(QList<T>::Node*, const T&) [with T = Point]':
    16. /usr/include/QtCore/qlist.h:332: note: synthesized method 'Point& Point::operator=(const Point&)' first required here
    17. gmake: *** [linestring.o] Error 1
    18. *** Exited with status: 2 ***
    To copy to clipboard, switch view to plain text mode 
    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?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem with my object hierarchy

    QList makes copies. You can't add QObjects to a QList but you can add pointers to QObjects.
    Qt Code:
    1. QList<QObject> list1; // <-- not ok
    2. QList<QObject*> list2; // <-- ok
    To copy to clipboard, switch view to plain text mode 

    PS. Copying objects and inheritance are different concepts.
    J-P Nurmi

Similar Threads

  1. Getting std::string object from QString object ( qt3)
    By joseph in forum Qt Programming
    Replies: 11
    Last Post: 28th March 2013, 20:09
  2. Replies: 3
    Last Post: 15th April 2007, 19:16
  3. Can't create an object : initialisation problem ?
    By Nyphel in forum Qt Programming
    Replies: 5
    Last Post: 12th March 2007, 09:07
  4. QT4 scope problem
    By the_bis in forum Newbie
    Replies: 5
    Last Post: 29th January 2007, 23:01
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.