PDA

View Full Version : QList inside a QList



jano_alex_es
1st July 2009, 11:47
Hi,

I have a QList integrated with other QList<QPointF>, but it's impossible to add elements to the second QList.

For instance, the next code does not compile (2 overloads have no legal conversion for "this" pointer), but it should...



//Please note the blank space between the two ">"
QList<QList<QPointF> > my_list;
QPointF my_point(0, 10);
my_list.at(0).append(my_point);


then... how can I add elements to a lists of lists in qt? is it possible?

jano_alex_es
1st July 2009, 11:56
my bad, I just need to create a new QList<QPointF> and append it to the "big one". Is quite stupid to try to add an element inside a QList at the position zero when inside the zero position there is nothing :(

gsmiko
1st July 2009, 11:59
Hi jano_alex_es!

It is possible, the only problem is that QList::at returns a const reference to the item, use the [] operator instead. Of course, a new list should be added to my_list first.



QList<QList<QPointF> > my_list;
QList<QPointF> my_subList;
QPointF my_point(0, 10);
my_list.append(my_subList);
my_list[0].append(my_point);

It's not the best example, because my_point could be added to my_subList, and then my_subList to my_list.