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

QSqlRelationalDelegate displays EditRole's value instead of DisplayRole's in QComboBox

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 5.5.1, 5.8.0
    • Fix Version/s: 5.12.0 Alpha
    • Component/s: SQL Support
    • Labels:
      None
    • Commits:
      b92db8a4adf985fe842ec0693e17c81d9e816b93

      Description

      Making a combobox displaying a relational field of a QSqlRelationalTableModel editable, causes the combobox's QLineEdit to display the EditRole (ID field) instead of the DisplayRole.

      I think there is some fundamental issue related to this: QSqlRelationalTableModel::data(*, Qt::EditRole) initially (i.e. directly after select()) returns the display value, while it returns the edit value after the first edit. This is inconsistent and doesn't comply to the documentation, which states that the EditRole should indeed return the value of the original table - not the referenced one.

      This causes the model to become dirty when the very same combobox item has been selected, even though nothing has changed.
      Additionally, after editing, an editor will display the wrong value.
      I think, QSqlRelationalDelegate should always fetch the DisplayValue in setEditorData().

      The problem can be easily reproduced using the book example:
      http://doc.qt.io/qt-5/qtsql-books-example.html, making e.g. the author combobox editable.

      Attached is a quick hack to the QSqlRelationalDelegate. However, as said, I think the problem is more fundamental.

        Attachments

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

          Activity

            People

            Assignee:
            andysh Andy Shaw
            Reporter:
            rhaschke Robert Haschke
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes