PDA

View Full Version : QList of QLists



m15ch4
21st January 2010, 20:40
Welcome!

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


QList<QList<int> > myList;

but it doesn't compile.

Please help!

john_god
21st January 2010, 22:22
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

aamer4yu
22nd January 2010, 05:43
Can you show what compilation error you are getting ?

vishwajeet.dusane
22nd January 2010, 06:26
Try this




QList<int> myIntList;

QList<myIntList> listOFIntList;

jano_alex_es
22nd January 2010, 09:04
QList<QList<int> > myList;

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

bender86
22nd January 2010, 09:37
typedef QList<YourType> TypeList; // Type definition
...
QList<TypeList> list; // Variable definition.

Or, you could try this way (notice the spaces):
QList< QList<YourType> > list;

jano_alex_es
22nd January 2010, 09:42
The first blank space is not needed, with the second is enough.

mirelon
23rd January 2010, 03:05
the second blank is important - if there is two consecutive '>', it is parsed as '>>', which is an operator

m15ch4
24th January 2010, 10:15
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;

*Baby*
16th October 2013, 18:42
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;

anda_skoa
16th October 2013, 19:26
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,
_

stampede
16th October 2013, 20:34
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.

wysota
16th October 2013, 23:36
Exactly. For example, in gcc (4.7.x and above) you can add "-std=c++11" switch to enable it.

Or

CONFIG += c++11

to your project configuration file (in Qt5).