Results 1 to 7 of 7

Thread: Whats wrong with QList<QGraphicsItem>

  1. #1
    Join Date
    Sep 2009
    Posts
    30
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Whats wrong with QList<QGraphicsItem>

    Under gcc:
    Qt Code:
    1. #include <QtGui>
    2. #include <QtCore>
    3.  
    4. class test
    5. {
    6. public:
    7. test()
    8. : list( QList<QGraphicsLineItem>() )
    9. { }
    10.  
    11. private:
    12. QList<QGraphicsLineItem> list;
    13. };
    14.  
    15. int main(int argc, char *argv[])
    16. {
    17. QApplication app(argc, argv);
    18.  
    19. test t;
    20.  
    21. return app.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 

    returns:
    Qt Code:
    1. In file included from ..\Qt\include/QtCore/qlist.h:1,
    2. from ..\Qt\include/QtCore/../../src/corelib/kernel/qobject.h:50,
    3. from ..\Qt\include/QtCore/qobject.h:1,
    4. from ..\Qt\include/QtCore/../../src/corelib/io/qiodevice.h:46,
    5. from ..\Qt\include/QtCore/qiodevice.h:1,
    6. from ..\Qt\include/QtCore/../../src/corelib/xml/qxmlstream.h:45,
    7. from ..\Qt\include/QtCore/qxmlstream.h:1,
    8. from ..\Qt\include/QtCore/QtCore:3,
    9. from ..\Qt\include\QtGui/QtGui:3,
    10. from main.cpp:1:
    11. ..\Qt\include/QtGui/../../src/gui/graphicsview/qgraphicsitem.h: In member function 'void QList<T>::node_copy(QList<T>::Node*, QList<T>::Node*, QList<T>::Node*) [with T = QGraphicsLineItem]':
    12. ..\Qt\include/QtCore/../../src/corelib/tools/qlist.h:606: instantiated from 'void QList<T>::detach_helper() [with T = QGraphicsLineItem]'
    13. ..\Qt\include/QtCore/../../src/corelib/tools/qlist.h:114: instantiated from 'QList<T>::QList(const QList<T>&) [with T = QGraphicsLineItem]'
    14. main.cpp:8: instantiated from here
    15. ..\Qt\include/QtGui/../../src/gui/graphicsview/qgraphicsitem.h:865: error: 'QGraphicsLineItem::QGraphicsLineItem(const QGraphicsLineItem&)' is private
    16. ..\Qt\include/QtCore/../../src/corelib/tools/qlist.h:370: error: within this context
    17. ..\Qt\include/QtGui/../../src/gui/graphicsview/qgraphicsitem.h:865: error: 'QGraphicsLineItem::QGraphicsLineItem(const QGraphicsLineItem&)' is private
    18. ..\Qt\include/QtCore/../../src/corelib/tools/qlist.h:383: error: within this context
    To copy to clipboard, switch view to plain text mode 

    Doing the same thing, but replacing QGraphicsLineItem with int or anything else works... I'm at a loss

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Whats wrong with QList<QGraphicsItem>

    Have you tried a list of references or pointers rather than a list of values?

  3. #3
    Join Date
    Sep 2009
    Posts
    30
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Whats wrong with QList<QGraphicsItem>

    QList<QGraphicsItem &>
    fails because you can't new a reference

    QList<QGraphicsItem *>
    works, but I'm starting to think I should go about this differently.

    Here's the thing:
    I'm trying to make a QPlotAxis inherits QPlotItem inherits QGraphicsItem. The Axis containts the arrow (axis itself) and the labels (lines and text). I thought, well make a QList<QGraphicsLineItem> for the arrow, one for the markings (adaptive of window size) and a QList<QGraphicsTextItem> for the labels and axis name and work with that, but I guess it won't let me. What are the repercussions of working with a pointer list vs a normal one?

    Or I could do it this way: create QPainterPath that does it all?

    Thanks
    Last edited by rubenvb; 21st January 2010 at 20:30.

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Whats wrong with QList<QGraphicsItem>

    QList<SomeClass> requiers SomeClass to have assignment operator (=) to make a copy of it.
    Since QGraphicsItem doesnt seem to have it, you cannot use it directly in QList<QGraphicsItem> .
    QList<QGraphicsItem*> is good, theres no problem with it.

  5. #5
    Join Date
    Jan 2009
    Location
    The Netherlands and Spain
    Posts
    150
    Thanks
    6
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Whats wrong with QList<QGraphicsItem>

    Your answer made me search the docs because I couldn't remember having read something like that, while your explanation does make sense...
    Finally, I found a very interesting section:
    http://qt.nokia.com/doc/4.6/containe...tainer-classes

    Just posting for future reference...

  6. #6
    Join Date
    Sep 2009
    Posts
    30
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Whats wrong with QList<QGraphicsItem>

    Ah, great link!

    If you attempt to instantiate a QList<QWidget>, the compiler will complain that QWidget's copy constructor and assignment operators are disabled. If you want to store these kinds of objects in a container, store them as pointers, for example as QList<QWidget *>.
    That says it all

    Thanks, should have read the docs better, again...

  7. #7
    Join Date
    Oct 2009
    Location
    Mexico
    Posts
    81
    Thanks
    6
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Whats wrong with QList<QGraphicsItem>

    The QGraphicsItem is a abstrac class and can't be used directly, QGraphicsItem::paint ()is a pure virtual function, so you can't create a object of this class. QGraphics is used as a base class

    because of this..

    Qt Code:
    1. QList<QGraphicsItem> //don't compile. can't create a object of a abstract class
    2. QList<QGraphicsItem *> // works because is posible create a pointer of a abstract class, polymorphism
    3. QList<SubclassGraphicsItem> //works because the class is not abstract
    To copy to clipboard, switch view to plain text mode 
    Last edited by ecanela; 22nd January 2010 at 20:12. Reason: updated contents

Similar Threads

  1. Whats a manifest file for vc++
    By tgreaves in forum General Programming
    Replies: 4
    Last Post: 14th May 2012, 10:46
  2. Copying an QList into a new, sorted QList.
    By Thomas Wrobel in forum Newbie
    Replies: 3
    Last Post: 11th January 2010, 19:27
  3. Whats wrong with this script -- help needed
    By swamyonline in forum Qt Programming
    Replies: 5
    Last Post: 2nd July 2009, 14:17
  4. Whats This box too small
    By bruccutler in forum Qt Programming
    Replies: 5
    Last Post: 31st March 2007, 00:52
  5. Replies: 1
    Last Post: 18th March 2006, 17:37

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.