Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to find the source of problem: QList<T>::at: “index out of range”
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.8k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hoaeixpz
    wrote on last edited by
    #1

    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?
    Thanks

    1 Reply Last reply
    0
    • A Offline
      A Offline
      ambershark
      wrote on last edited by
      #2

      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.

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      H 1 Reply Last reply
      4
      • A ambershark

        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.

        H Offline
        H Offline
        hoaeixpz
        wrote on last edited by
        #3

        @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.

        mrjjM 1 Reply Last reply
        0
        • H hoaeixpz

          @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.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @hoaeixpz
          Hi
          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
          http://doc.qt.io/qtcreator/creator-debug-mode.html
          .

          1 Reply Last reply
          4

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved