Results 1 to 3 of 3

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

  1. #1
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

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

    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>:perator[]: "index out of range", file.
    i couldnt move to next step
    can any one give me suggestion for this
    Thanks in Advance

  2. #2
    Join Date
    Nov 2007
    Posts
    55
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ASSERT failure in QList<T>::operator[]: "index out of range", file

    you are trying to read data ot of bounds.

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

    Alain

  3. The following user says thank you to alainstgt for this useful post:

    iswaryasenthilkumar (3rd March 2015)

  4. #3
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: ASSERT failure in QList<T>::operator[]: "index out of range", file

    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:
    Qt Code:
    1. QList<MyItem> mylist; // mylist has now size 0
    2.  
    3. for( int i = 0; i < 5; i++ )
    4. {
    5. mylist[i] = something; // fail! The list has size 0 still. No items added on the list.
    6. }
    To copy to clipboard, switch view to plain text mode 
    You must append first:
    Qt Code:
    1. QList<MyItem> mylist; // mylist has now size 0
    2.  
    3. for( int i = 0; i < 5; i++ )
    4. {
    5. 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
    6. }
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to Radek for this useful post:

    iswaryasenthilkumar (3rd March 2015)

Similar Threads

  1. Replies: 0
    Last Post: 9th January 2015, 10:09
  2. Replies: 5
    Last Post: 20th November 2013, 10:20
  3. Replies: 5
    Last Post: 29th September 2012, 19:30
  4. Replies: 3
    Last Post: 26th September 2012, 20:21
  5. Replies: 3
    Last Post: 27th July 2011, 09:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.