What may be the cause of following error?



  • @ASSERT failure in QList<T>::at: "index out of range"@



  • I believe you are passing an index position that doesn't exist. I mean for example that your QList has only five elements and you are trying to access the sixth.

    const T & QList::at ( int i ) const

    Returns the item at index position i in the list. i must be a valid index position in the list (i.e., 0 <= i < size())



  • [quote author="Josué V. Herrera" date="1324275775"]I believe you are passing an index position that doesn't exist. I mean for example that your QList has only five elements and you are trying to access the sixth.

    const T & QList::at ( int i ) const

    Returns the item at index position i in the list. i must be a valid index position in the list (i.e., 0 <= i < size())[/quote]
    ok thanks i will check it.



  • Worth mentioning that you'll see mainly two behaviours with Qt containers (as for example QList):

    • at() and operator[] asserts on invalid indices,
    • value() does not assert on invalid indices, it returns a default-constructed value instead.

    If you use both your code may or may not assert, depending on which method you use, even though your code causes acccess to an invalid index.



  • Watch out, operator[] does assert!



  • Right: the difference isn't the lack of assertions (both methods have them) -- the difference is the copy functionality. From the documentation: "at() can be faster than operator, because it never causes a deep copy to occur."


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.