Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-51011

QModelIndex::internalId() returns qint64, NOT quintptr as documented

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.4.1
    • Core: Object Model
    • None
    • Windows 32-bit platforms (maybe also on Mac 32-bit systems)

    Description

      Per the documentation for QModelIndex::internalId():

      quintptr QModelIndex::internalId() const

      Returns a quintptr used by the model to associate the index with the internal data structure.

      See also QAbstractItemModel::createIndex().

      However, the actual code for this function is:

      inline qint64 internalId() const { return reinterpret_cast<qint64>(p); }
      

      The problem is, specifically on 32-bit systems, quintptr is not qint64.

      For that matter, according to the documentation for quintptr, even on 64 bit systems, quintptr is not qint64. Per the documentation:

      typedef quintptr
      Integral type for representing pointers in an unsigned integer (useful for hashing, etc.).

      Typedef for either quint32 or quint64. This type is guaranteed to be the same size as a pointer on all platforms supported by Qt. On a system with 32-bit pointers, quintptr is a typedef for quint32; on a system with 64-bit pointers, quintptr is a typedef for quint64.

      Note that quintptr is unsigned. Use qptrdiff for signed values.

      See also qptrdiff, quint32, and quint64.

      This signed vs. unsigned difference is significant. consider the following:

      static const quintptr   MAGIC_VALUE = static_cast<quintptr>(0xFFFFFFFFFFFFFFFFULL);   // set this for both 32- and 64-bit platforms
      
      ...
      
      QModelIndex  index(CreateIndexWithMagicValue());
      
      ...
      
      if (index.internalId() != MAGIC_VALUE)
      {
          Q_ASSERT(false);
      }
      

      Assuming that CreateIndexWithMagicValue() properly creates an index with MAGIC_VALUE as its internal ID, the above code will assert under all conditions on a 32-bit platform (where it was tested), and should at least cause a compiler error about mismatched comparisons on a 64-bit platform.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            jb4 Jay Burns IV
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes