Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
6.5.5, 6.6.3, 6.7.0
Description
How to reproduce:
1. Declare QSet<QVariant> instance. ("QSet<QVariant> hash" in the reproducer)
2. Generate QPersistentModelIndex with the same QModelIndex, and insert it to the QSet<QVariant> instance. ("hash.insert(QPersistentModelIndex(model.index(0, 0)));")
3. Repeat the step 2.
With Qt 6, repeating 64 times makes the application crash. With Qt 5, the application can repeat it through 3000 times.
Comments/questions/requirements from the customer:
- The cause of this issue is as follows :
1. When QHash tries to compare hash values generated from QVariant, it calls qHashEquals().
2. This uses "QPersisnteModelIndex::operator==" for the comparison of two QVariants, instead of "QPersisnteModelIndex::qHashEquals".
- The document of QHash Class says "if e1 == e2, then hash(e1) == hash(e2) must hold as well". However due to the implementation of QPersistentModelIndex, "hash(e1) != hash(e2)" can happen even when "e1==e2". Thus I think using qHashEquals must be important. Nevertheless, qHashEquals is NOT described in the Qt document. Please add a description about it to the document.
- Is it OK to use qHashEquals with specialization?
If specialization is allowed, we want to implement it to call QPersistentModelIndex::qHashEquals when the both sides of the comparison are QPersistentModelIndex.
If there is a better way than the specialization, please provide it.