How view whole data from SQLlite table
Solved
QML and Qt Quick
-
I have a problem with view data form database.
In my QML application I would like to view whole data from SQLite table. Currently only displayed one (first) column, but in my table I have three of themMy file main.cpp is below:
DbManager db("C:\\sqlite\\db\\database.db"); QSqlQueryModel *someSqlModel = new QSqlQueryModel(); someSqlModel->setQuery("SELECT * FROM sale"); engine.rootContext()->setContextProperty("datamodel", someSqlModel);
My file main.qml is below:
Rectangle { ListView { anchors { left: parent.left top: parent.top leftMargin: 50 topMargin: 50 } width: 800 height: 1000 model: datamodel delegate: Row { Rectangle { width: 200 height: 40 Text { anchors.fill: parent text: display } } } } }
Any idea what I do wrong ?
-
In the above code just change List View to TableView
I have other problem . When the someSqlModel I have in main.cpp everything works ok.
Now I moved someQglModel to another class, and this class I exposed to QML:engine.rootContext()->setContextProperty("dbManager",dbManager);
And in my QML code I try get model to TableView by:
model: dbManager.someSqlModel
but it doesn't work, any idea ?
-
Hi,
You should share the code of your DbManager class.
-
May be you missed creating the someSqlModel object itself ? Is someSqlModel local object ?
-