Hi @zain_a,
The example you've copied from the Qt docs is demonstrating how/why to use QContiguousCache::normalizeIndexes(), if needed, but it's not saying definitively that it is always needed. It's platform dependant.
QContiguousCache::areIndexesValid() says:
Indexes can become invalid if items are appended after the index position INT_MAX or prepended before the index position 0.
Note, that it can become invalid, not that it necessarily will. In this case, it depends on the difference (if any) between the old C INT_MAX and Qt's qsizetype (which is usually derived from std::size_t, which may or may not match INT_MAX').
Try this, for example:
qDebug() << INT_MAX;
qDebug() << std::numeric_limits<qsizetype>::max();
For me, on a 64-bit Linux system with gcc, I get:
2147483647
9223372036854775807
But on platforms where those two are the same, then your example will probably print false as you expected. All that to say, just use the QContiguousCache::areIndexesValid() method and act accordingly. Leave the underlying platform handling to Qt :)
Cheers.