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

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P2: Important P2: Important
    • 5.12.0 Alpha
    • 5.5.1, 5.8.0
    • SQL Support
    • None
    • b92db8a4adf985fe842ec0693e17c81d9e816b93

      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.

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

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

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes