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. how to add data dynamicaly to a qabstracttablemodel and use it on qml tableview
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 276 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.
  • H Offline
    H Offline
    haseeb india
    wrote on last edited by haseeb india
    #1

    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();
    }

    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