Results 1 to 13 of 13

Thread: QList of QLists

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

    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
    Thanks
    23
    Thanked 32 Times in 28 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    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
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QList of QLists

    Can you show what compilation error you are getting ?

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

    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
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    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
    Thanked 21 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Windows

    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
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    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
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    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
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    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
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    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,
    _

  12. #12
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QList of QLists

    I do believe, however, that with C++11 this is parsed correctly
    Exactly. For example, in gcc (4.7.x and above) you can add "-std=c++11" switch to enable it.

  13. #13
    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: QList of QLists

    Quote Originally Posted by stampede View Post
    Exactly. For example, in gcc (4.7.x and above) you can add "-std=c++11" switch to enable it.
    Or

    qmake Code:
    1. CONFIG += c++11
    To copy to clipboard, switch view to plain text mode 

    to your project configuration file (in Qt5).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.