Reputation: 662
I have a QList for store some item on QgraphicsScene like:
QList<QGraphicsItem*> lineList;
when I want to use it like:
lineList[itemIndex++]=scene->createItemGroup(groupItems);
i got a runtime error. I'm curios why?
by the way I know about linelist.append()
thanks.
Upvotes: 1
Views: 222
Reputation: 2969
Assuming that itemIndex++
is equals or below to lineList.size()
, you can use QList::insert
lineList.insert(itemIndex++, scene->createItemGroup(groupItems));
Anyway, it is preferable to use append
for extending your list by one unit.
Upvotes: 1
Reputation: 4195
Assuming that you want to create a new QList, you should use QList::append() or << operator
. From Qt Docs:
T & QList::operator[](int i) Returns the item at index position i as a modifiable reference. i must be a valid index position in the list (i.e., 0 <= i < size()). This function is very fast (constant time). See also at() and value().
So QList::operator[]
can't be used to populate list like that.
Upvotes: 5