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. What may be the cause of following error?

What may be the cause of following error?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 5 Posters 2.5k Views 1 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.
  • P Offline
    P Offline
    pratik041
    wrote on last edited by
    #1

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

    Pratik Agrawal

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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())

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pratik041
        wrote on last edited by
        #3

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

        Pratik Agrawal

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dangelog
            wrote on last edited by
            #5

            Watch out, operator[] does assert!

            Software Engineer
            KDAB (UK) Ltd., a KDAB Group company

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Chris H
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0

              • Login

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