Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Table view UI update



  • Hi guys

    I am using Table view.. and trying to update my table view..

    TableView {
    model: TableModel {}
    }
    
    
    **main.cpp**
    qmlRegisterType<TableModel>("TableModel", 0, 1, "TableModel");
    
    
    **TableModel.h**
    QVector<QVector<QString>> m_Model;
    
    
    **TableModel.cpp**
    
    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");
    }
    

    But my UI is not getting updated
    How can I solve this issue?

    Thanks!!!



  • @ashajg said in Table view UI update:

    But my UI is not getting updated

    does this mean that it still shows the old values or just displays nothing at all?



  • Hi @VRonin

    Thanks for reply!!!

    Its Still Showing same values..



  • can you try changing emit dataChanged(start, indexPos, {role}); to emit dataChanged(indexPos, indexPos);?

    P.S.
    Your setData doesn't seem to manage roles correctly but this is another, separate, problem



  • ok I ll try that..


Log in to reply