Just guessing: Note that operator [ ] ( int i ) can reference only list items already added to the list but it cannot add items to the list. To build the list, use append(). For example:
QList<MyItem> mylist; // mylist has now size 0
for( int i = 0; i < 5; i++ )
{
mylist[i] = something; // fail! The list has size 0 still. No items added on the list.
}
QList<MyItem> mylist; // mylist has now size 0
for( int i = 0; i < 5; i++ )
{
mylist[i] = something; // fail! The list has size 0 still. No items added on the list.
}
To copy to clipboard, switch view to plain text mode
You must append first:
QList<MyItem> mylist; // mylist has now size 0
for( int i = 0; i < 5; i++ )
{
mylist.append(something); // ok. mylist size = 5 at the end of the cycle. Now, it is ok to use mylist[i] for i = 0,1, ..., 4
}
QList<MyItem> mylist; // mylist has now size 0
for( int i = 0; i < 5; i++ )
{
mylist.append(something); // ok. mylist size = 5 at the end of the cycle. Now, it is ok to use mylist[i] for i = 0,1, ..., 4
}
To copy to clipboard, switch view to plain text mode
Bookmarks