Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
5.4.1
-
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.