Results 1 to 8 of 8

Thread: QList of a QList

  1. #1
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default QList of a QList

    Why am I not able to create a QList of QList's?
    Ex:
    Qt Code:
    1. QList<QList> * tileList;
    2. Error:
    3. type/value mismatch at argument 1 in template parameter list for 'template<class T> class QList'
    4. expected a type, got 'QList'
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QList of a QList

    Every QList requires a type, so also the second one.

  3. #3
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QList of a QList

    Every QList requires a type, so also the second one.
    What do you mean by that?

  4. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QList of a QList

    He meant something like this:
    QList<QList<some_type> > list; // notice the space within '>' and '>'

  5. #5
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QList of a QList

    Quote Originally Posted by Zlatomir View Post
    He meant something like this:
    QList<QList<some_type> > list; // notice the space within '>' and '>'
    Ok, but how can I add a QList?
    Ex:
    Qt Code:
    1. QList< QList<int> > * tileList;
    2.  
    3. QList<int> list;
    4.  
    5. tileList << list;
    To copy to clipboard, switch view to plain text mode 

    Gives an error:
    Qt Code:
    1. error: no match for 'operator<<' in '((Widget*)this)->Widget::tileList << rowList'
    2.  
    3. note: candidates are: QDataStream& operator<<(QDataStream&, const QChar&)
    4. //Huge list follows.....
    To copy to clipboard, switch view to plain text mode 

    Edit: If I use:
    Qt Code:
    1. tileList->append(rowList);
    To copy to clipboard, switch view to plain text mode 
    The application crashes with "Invalid parameter passed to C runtime function.
    Invalid parameter passed to C runtime function.
    "
    Last edited by been_1990; 8th November 2010 at 20:23.

  6. #6
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QList of a QList

    That's because your list of lists is actually a pointer to a list of lists - a pointer which you never allocate or initialize. Lose the '*'.

  7. #7
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QList of a QList

    Or use something like:
    Qt Code:
    1. QList<QList<int> > *list = new QList<QList<int> >;
    To copy to clipboard, switch view to plain text mode 
    if you really need it on the heap.

    And read a little about pointers, if you have int *p; you can't legally use p because it points to an unspecified location.

    You need an object and a pointer, something like:
    int number = 10; int *p = &number;
    or use the pointer to create an object on the heap (that object doesn't have a name, but it is there):
    int *p = new int(10);

  8. #8
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QList of a QList

    You are right. I forgot. Thanks for the lesson.
    Last edited by been_1990; 8th November 2010 at 21:01.

Similar Threads

  1. Cast QList<Foo*> to QList<const Foo*>
    By vfernandez in forum Qt Programming
    Replies: 0
    Last Post: 4th October 2010, 16:04
  2. Replies: 4
    Last Post: 20th August 2010, 13:54
  3. Copying an QList into a new, sorted QList.
    By Thomas Wrobel in forum Newbie
    Replies: 3
    Last Post: 11th January 2010, 18:27
  4. QList: Out of memory - without having defined QList
    By miroslav_karpis in forum Qt Programming
    Replies: 1
    Last Post: 27th March 2009, 08:42
  5. QList<QList > question
    By SubV in forum Qt Programming
    Replies: 3
    Last Post: 25th July 2008, 15:14

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.