PDA

View Full Version : ASSERT failure in QList<T>::operator[]: "index out of range", file



iswaryasenthilkumar
2nd March 2015, 13:16
am using QString list to get list of files from one folder and copying these files in another folder.my files are copied bt i geting error as
ASSERT failure in QList<T>::operator[]: "index out of range", file.
i couldnt move to next step
can any one give me suggestion for this :confused:
Thanks in Advance:o

alainstgt
2nd March 2015, 14:26
you are trying to read data ot of bounds.

Compare the size of your list ( myList.size() ) with the argument passed to operator[]

Alain

Radek
2nd March 2015, 15:27
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.
}

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
}