how to add data dynamicaly to a qabstracttablemodel and use it on qml tableview



  • how to add data dynamicaly to a qabstractmodel and use it on qml tableview
    qml_code
    ApplicationWindow {
    visible: true
    width: 660
    height: 620
    Data_Class{
    id:data}
    title: qsTr("TableModel sample")
    ColumnLayout{

    TextField{
        width:100
        height:50
        id:"text1"
    }
    TextField{
        width:100
        height:50
     id:"text2"
    }
    Button{
        width:50
         height:50
     id:"addbutton"
    text:"ADD"
    onClicked:
    {
        data.addEntry(text1.text,text2.text)
    }
    }
    
    TableView {
    
        model: tableModel
        TableViewColumn {
            role: "currency"
            title: "Currency"
            width: 180
        }
        TableViewColumn {
            role: "symbol"
            title: "Symbol"
            width: 180
        }
    
    }
    

    }}
    main_cpp
    int main(int argc, char *argv[])
    {
    QGuiApplication app(argc, argv);
    qmlRegisterType<data_class>("org.sdc.data_class", 1,0, "Data_Class");
    QQmlApplicationEngine engine;
    TableModel *tableModel=new TableModel;
    engine.rootContext()->setContextProperty("tableModel", tableModel);
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    return app.exec();
    }


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.