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

QHash: Document qHashEquals

    XMLWordPrintable

Details

    • Windows

    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.

      Attachments

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

        Activity

          People

            docteam Qt Documentation Team
            hitoshiito Hitoshi Ito
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes