March 19, 2011

chronoske chronoske
Lab Rat
31 posts

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?
1. Can I link Qml with database?
2. Or should I use a javascript for it?
3. 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.
Regards.

4 replies

March 20, 2011

ZapB ZapB
Robot Herder
1359 posts

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.

 Signature 

Nokia Certified Qt Specialist
Interested in hearing about Qt related work

March 21, 2011

mbrasser mbrasser
Ant Farmer
452 posts

Hi,

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:

Regards,
Michael

March 21, 2011

chronoske chronoske
Lab Rat
31 posts

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. =)

March 24, 2011

chronoske chronoske
Lab Rat
31 posts

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.

 
  ‹‹ [Announcement] QtMongo: access to MongoDB from QML      Getting item from Grid? ››

You must log in to post a reply. Not a member yet? Register here!