View Full Version : QList of a QList
been_1990
8th November 2010, 17:36
Why am I not able to create a QList of QList's?
Ex:
QList<QList> * tileList;
Error:
type/value mismatch at argument 1 in template parameter list for 'template<class T> class QList'
expected a type, got 'QList'
tbscope
8th November 2010, 17:51
Every QList requires a type, so also the second one.
been_1990
8th November 2010, 18:14
Every QList requires a type, so also the second one.
What do you mean by that?
Zlatomir
8th November 2010, 18:18
He meant something like this:
QList<QList<some_type> > list; // notice the space within '>' and '>'
been_1990
8th November 2010, 20:19
He meant something like this:
QList<QList<some_type> > list; // notice the space within '>' and '>'
Ok, but how can I add a QList?
Ex:
QList< QList<int> > * tileList;
QList<int> list;
tileList << list;
Gives an error:
error: no match for 'operator<<' in '((Widget*)this)->Widget::tileList << rowList'
note: candidates are: QDataStream& operator<<(QDataStream&, const QChar&)
//Huge list follows.....
Edit: If I use:
tileList->append(rowList);
The application crashes with "Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function."
SixDegrees
8th November 2010, 20:24
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 '*'.
Zlatomir
8th November 2010, 20:32
Or use something like:
QList<QList<int> > *list = new QList<QList<int> >;
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);
been_1990
8th November 2010, 21:01
You are right. I forgot. Thanks for the lesson. :)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.