Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Linking Qt Quick with SQLite
Hello there, i'd like to ask for some information regarding linking Qt Quick with SQLite. I wish to display some tables and charts, and the raw data would be from the database. The problem is that I haven't found any example of the qml code, I did found some links but unfortunately all of them are using the cpp instead. I have also done some research of the same game code, but the database ended up in an unknown file name in the directory C:\Documents and Settings\user\Local Settings\Application Data\Nokia\QtQmlViewer\QML\OfflineStorage\Databases.
Can someone help me?
- Can I link Qml with database?
- On http://doc.qt.nokia.com/4.7-snapshot/declarative-sqllocalstorage-hello-qml.html, there is a code for database in qml but it was save on the above directory, can that be changed?
hanks for your consideration.
ZapB last edited by
Why not create a c++ object for handling the database io and then expose that object to the QML side where you can bind it to properties in your scene?
For example I think I would try the approach of using QSqlTableModel or QSqlQueryModel and then binding this to a ListView element or similar in QML.
mbrasser last edited by
You can change the local storage directory via QDeclarativeEngine, see http://doc.qt.nokia.com/4.7-snapshot/qdeclarativeengine.html#offlineStoragePath-prop for details (http://doc.qt.nokia.com/4.7-snapshot/qdeclarativeglobalobject.html#offline-storage-api also gives general information on the offline storage API, if you have not seen it already).
The following threads give some additional detail on the naming/path of the local storage database:
Whoah, big thanks to both of you, it seems that the program has run well, and now i'm working on my tables. Though there's something that I would ask again, is it possible to change the directory and the file name of the offline storage database? Both the directory and the file name are frustating indeed. ZapB, I'm thinking of learning the c++ qt straight after I finished this project, the problem is that I tried the Qml in the first place and I feel great with the feature. =)
One more question, if I may, in Qt c++, there is a function of db.setDatabaseName("mydatabase") and as the name suggest, this function is used to change the database name into mydatabase. The question is, what is the qml version of this syntax?
And, thanks for reading.