Qt World Summit: Submit your Presentation

how to find the source of problem: QList<T>::at: “index out of range”

  • Hello everyone.
    I met a problem when i debug my code,there is an error appers QList<T>::at: “index out of range”,
    I know it is because that i'm tring to access an index that isn't exist.But There are many QList object in my code ,i don't know which List is wrong,how can i find the source of the problem?

  • Hi. If you run it in debug mode it will Q_ASSERT which will throw an assertion you can catch in the debugger (i.e. gdb) and then do a backtrace and find exactly which piece of code had the bad index.

  • @ambershark Thank you very much.Actually I have used the Q_ASSERT in debug mode,but I think it is very bother.The problem I meet today is the "index out of range" about QList , so I can insert Q_ASSERT before every qlist variable,but if I meet other problem,how can I know what kind of problem get wrong.

  • Lifetime Qt Champion

    You dont need to insert Q_ASSERT in your code.
    The error "out of range" is a Q_ASSERT
    So what @ambershark is saying is that if you start your application in debug mode in creator.
    Then when it crashes, there is a list over called functions (call stack/backtrace) which might show
    exactly where it crashes

Log in to reply