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

Can not edit QSqlTableModel from QML TableView

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • Not Evaluated
    • None
    • 5.15.0
    • Core: Item Models
    • None
    • All

    Description

      Hi guys, 

      I find that, it is impossible to edit QSqlTable in QML's TableView. 

      The document said that , use model.edit can locate the edit role, and modify it. 

      But the fact is that, the QSQlTableModel inherit QSqlQueryModel, but did not rewrite the rolenames function, So it only have DisplayRole. So it can not recognize the "edit" key word.

      I inherit QSqlTableModel, and rewrite the rolenames fucntion.added a Edit role, and it works. 

      // code placeholder
      QHash<int, QByteArray> MySqlTableModel::roleNames() const
      {
          return  QHash<int,QByteArray>{
              {Qt::DisplayRole, QByteArrayLiteral("display")},
              {Qt::EditRole, QByteArrayLiteral("edit")}
          };
      
      }
      

       

      Attachments

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

        Activity

          People

            dfaure_kdab David Faure
            yorkchenqt1989 York Chen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes