Results 1 to 3 of 3

Thread: problem with QList

  1. #1
    Join Date
    Feb 2008
    Posts
    102
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question problem with QList

    I have a list of QGraphicsScene*:

    QList<QGraphicsScene*>scenes;

    Each element of the list would be a pointer of type QGraphicsScene*....
    So scenes[i] return a QgraphicsScene* element????
    From the documentation:
    "On non-const lists, operator[]() returns a reference to the item".....so in my case, it will return a QGraphicsScene** element??

    I want to pass this list of scenes, to an other myclass object:
    Qt Code:
    1. myclass::myclass(QList<QGraphicsScene*> s){}
    To copy to clipboard, switch view to plain text mode 

    ...but the compiler gives me error if a write
    myclass(scenes)........
    Last edited by dreamer; 9th May 2008 at 19:03. Reason: updated contents

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problem with QList

    Quote Originally Posted by dreamer View Post
    So scenes[i] return a QgraphicsScene* element????
    Yes.


    "On non-const lists, operator[]() returns a reference to the item".....so in my case, it will return a QGraphicsScene** element??
    A reference, not a pointer. So QGraphicsScene*&, to be precise. It can be used as l-value and not r-value. For the latter you'll be using the const version and getting a regular pointer.

    ...but the compiler gives me error if a write
    myclass(scenes)........
    What kind of error?

  3. #3
    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: problem with QList

    Shouldn't
    myclass(scenes)
    be
    myclass myObject(scenes)
    ???

    Hope am right

Similar Threads

  1. Sorting using qSort(), - if QList contains POINTERS
    By joseph in forum Qt Programming
    Replies: 13
    Last Post: 18th August 2013, 18:55
  2. QList index out of range problem
    By MarkoSan in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2008, 08:40
  3. Replies: 3
    Last Post: 15th April 2007, 19:16
  4. Accessing QList Objects
    By magikalpnoi in forum Qt Programming
    Replies: 7
    Last Post: 21st September 2006, 20:43
  5. QList problem
    By acix in forum General Programming
    Replies: 6
    Last Post: 29th April 2006, 13:08

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.