Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Data() is not called after the table model changes in QAbstractTableModel even after using dataChanged()

Data() is not called after the table model changes in QAbstractTableModel even after using dataChanged()

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kradhika981
    wrote on last edited by kradhika981
    #1

    Even after I changed my tableModel and emitted dataChanged() UI did not
    update.
    Tried begin and endResetModel(), didn't help.
    Further from my debugging I see that after the model is changed, data() is not getting invoked.
    I Have used QVector<QVector<QString>> for model and am using TableView as part of QML.

    JonBJ 1 Reply Last reply
    0
    • K kradhika981

      Even after I changed my tableModel and emitted dataChanged() UI did not
      update.
      Tried begin and endResetModel(), didn't help.
      Further from my debugging I see that after the model is changed, data() is not getting invoked.
      I Have used QVector<QVector<QString>> for model and am using TableView as part of QML.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @kradhika981
      This is not a question, it's just a reference to some old post. If you have some question about that, you should state what it is, clearly.

      Reading through for you, if you cannot resolve the dataChanged() issue then answer https://forum.qt.io/topic/50720/solved-qml-problem-with-tableview-refresh-on-model-update/3 states that begin/endResetModel() works. Whether that is acceptable for your case no-one can know as you haven't said anything....

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kradhika981
        wrote on last edited by
        #3

        Hey, I am posting for the first time, so maybe some issue. Issue I am facing is as follows :

        1. Even after I changed my tableModel and emitted dataChanged() UI did not
          update.
        2. Tried begin and endResetModel(), didn't help.
        3. Further from my debugging I see that after the model is changed, data() is not getting invoked.

        I Have used QVector<QVector<QString>> for model and am using TableView as part of QML.

        JonBJ 1 Reply Last reply
        0
        • K kradhika981

          Hey, I am posting for the first time, so maybe some issue. Issue I am facing is as follows :

          1. Even after I changed my tableModel and emitted dataChanged() UI did not
            update.
          2. Tried begin and endResetModel(), didn't help.
          3. Further from my debugging I see that after the model is changed, data() is not getting invoked.

          I Have used QVector<QVector<QString>> for model and am using TableView as part of QML.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @kradhika981
          Since others report that (reset model at least) does work, I imagine you'll be asked to show a snippet of the relevant code you are using. We do not even know what it is you are changing in your model, and so whether dataChanged() is even the right signal....

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kradhika981
            wrote on last edited by
            #5

            QML :

            TableView {
            model: TableModel {}
            }
            

            main.cpp

            qmlRegisterType<TableModel>("TableModel", 0, 1, "TableModel");
            

            TableModel.h

            QVector<QVector<QString>> m_Model;
            

            TableModel.cpp

            // Here is where data is getting set 
            bool TableModel::setData(const QModelIndex &indexPos, const QVariant &value, int role)
            {
                if(data(indexPos, role) == value)
                    return false;
            
                QString key = m_Model.at(indexPos.row()).at(indexPos.column()-1);
                qDebug() << "KEY:" << key;
                m_Model.replace(indexPos.row(),{key, value});
                qDebug() << "Model Data Changed!!!" << m_Model;
                QModelIndex start = index(1,0);
                emit dataChanged(start, indexPos, {role});
                return true;
            }
            
            void changeModel() {
                   setData(index(1,1), "abc");
            }
            

            It is a table with two columns , a key value pair kind and the data change wil be triggered from cpp function changeModel() . Currently I was changing just the second row (1st row after header ) 2nd column value.

            So In the Output of qDebug() << "Model data Changed!!!" , I am seeing the new model, but UI is not getting updated.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved