Results 1 to 13 of 13

Thread: QList of QLists

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2010
    Location
    Poland Warsaw
    Posts
    25
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Default QList of QLists

    Welcome!

    I would like to ask if it is possible to create QList of QLists?
    I've tried to do something like this:

    Qt Code:
    1. QList<QList<int> > myList;
    To copy to clipboard, switch view to plain text mode 

    but it doesn't compile.

    Please help!

  2. #2
    Join Date
    Aug 2008
    Location
    Algarve, Portugal
    Posts
    288
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60
    Thanks
    23
    Thanked 32 Times in 28 Posts

    Default Re: QList of QLists

    I did something like that with some workaround. Just define a class, in that class define a qlist, and then define a qlist of that class. Works like charm
    __________________________________________________
    My projects: calculator MathGraphica ; SuperEpicMegaHero game ; GooglePlay ; bitbucket ; github
    Like my projects ? Buy me a kofi

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

    Default Re: QList of QLists

    Can you show what compilation error you are getting ?

  4. #4
    Join Date
    Sep 2009
    Posts
    72
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows
    Thanked 10 Times in 10 Posts

    Default Re: QList of QLists

    Try this


    Qt Code:
    1. QList<int> myIntList;
    2.  
    3. QList<myIntList> listOFIntList;
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 23rd January 2010 at 14:52.

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

    Default Re: QList of QLists

    QList<QList<int> > myList;

    This works fine, the problem should be somewhere else. Have you added the include?

  6. #6
    Join Date
    Nov 2007
    Posts
    89
    Qt products
    Qt4
    Platforms
    Windows
    Thanked 21 Times in 18 Posts

    Default Re: QList of QLists

    Qt Code:
    1. typedef QList<YourType> TypeList; // Type definition
    2. ...
    3. QList<TypeList> list; // Variable definition.
    To copy to clipboard, switch view to plain text mode 

    Or, you could try this way (notice the spaces):
    Qt Code:
    1. QList< QList<YourType> > list;
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: QList of QLists

    The first blank space is not needed, with the second is enough.

  8. #8
    Join Date
    Dec 2009
    Location
    Bratislava, Slovakia
    Posts
    11
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3

    Default Re: QList of QLists

    the second blank is important - if there is two consecutive '>', it is parsed as '>>', which is an operator

  9. #9
    Join Date
    Jan 2010
    Location
    Poland Warsaw
    Posts
    25
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Default Re: QList of QLists

    Hi!

    Thanks for your replies. I don't know where the problem was but now everything works. I'm using that version:
    QList<QList<int> > myList;

  10. #10
    Join Date
    Feb 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QList of QLists

    It seems only to work if there is a space between brackets.

    This works:
    QList<QList<int> > myList;
    QList< QList<int> > myList;

    This doesn't work:
    QList<QList<int>> myList;

  11. #11
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: QList of QLists

    mirelon already explained this. you need a space between the two > characters, otherwise the >> is seen as operator>>().

    I do believe, however, that with C++11 this is parsed correctly

    Cheers,
    _

Similar Threads

  1. Copying an QList into a new, sorted QList.
    By Thomas Wrobel in forum Newbie
    Replies: 3
    Last Post: 11th January 2010, 18:27
  2. QList inside a QList
    By jano_alex_es in forum Newbie
    Replies: 2
    Last Post: 1st July 2009, 11:59
  3. QList: Out of memory - without having defined QList
    By miroslav_karpis in forum Qt Programming
    Replies: 1
    Last Post: 27th March 2009, 08:42
  4. help using QLists as data in QwtPlotCurve
    By esorensen in forum Qwt
    Replies: 1
    Last Post: 11th July 2008, 19:52
  5. QList of Qlists?
    By markcole in forum Qt Programming
    Replies: 6
    Last Post: 8th July 2008, 05:44

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.