Results 1 to 3 of 3

Thread: QList inside a QList

  1. #1
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default QList inside a QList

    Hi,

    I have a QList integrated with other QList<QPointF>, but it's impossible to add elements to the second QList.

    For instance, the next code does not compile (2 overloads have no legal conversion for "this" pointer), but it should...

    Qt Code:
    1. //Please note the blank space between the two ">"
    2. QList<QList<QPointF> > my_list;
    3. QPointF my_point(0, 10);
    4. my_list.at(0).append(my_point);
    To copy to clipboard, switch view to plain text mode 

    then... how can I add elements to a lists of lists in qt? is it possible?

  2. #2
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: QList inside a QList

    my bad, I just need to create a new QList<QPointF> and append it to the "big one". Is quite stupid to try to add an element inside a QList at the position zero when inside the zero position there is nothing
    Last edited by jano_alex_es; 1st July 2009 at 13:08.

  3. #3
    Join Date
    Sep 2008
    Posts
    25
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QList inside a QList

    Hi jano_alex_es!

    It is possible, the only problem is that QList::at returns a const reference to the item, use the [] operator instead. Of course, a new list should be added to my_list first.


    Qt Code:
    1. QList<QList<QPointF> > my_list;
    2. QList<QPointF> my_subList;
    3. QPointF my_point(0, 10);
    4. my_list.append(my_subList);
    5. my_list[0].append(my_point);
    To copy to clipboard, switch view to plain text mode 

    It's not the best example, because my_point could be added to my_subList, and then my_subList to my_list.
    Last edited by gsmiko; 1st July 2009 at 13:20.

Similar Threads

  1. Sorting using qSort(), - if QList contains POINTERS
    By joseph in forum Qt Programming
    Replies: 13
    Last Post: 18th August 2013, 19:55
  2. QList, copy problems
    By Valheru in forum Qt Programming
    Replies: 4
    Last Post: 5th February 2010, 01:06
  3. Destroying a QList the right way
    By Cruz in forum Newbie
    Replies: 1
    Last Post: 19th January 2009, 11:52
  4. QList
    By dragon in forum Qt Programming
    Replies: 11
    Last Post: 9th May 2007, 21:15
  5. Accessing QList Objects
    By magikalpnoi in forum Qt Programming
    Replies: 7
    Last Post: 21st September 2006, 21:43

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.