Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Linking Qt Quick with SQLite

    QML and Qt Quick
    3
    5
    8339
    Loading More Posts
    • 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.
    • C
      chronoske last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • Z
        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.

        Nokia Certified Qt Specialist
        Interested in hearing about Qt related work

        1 Reply Last reply Reply Quote 0
        • M
          mbrasser last edited by

          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:

          • http://developer.qt.nokia.com/forums/viewthread/2093
          • http://developer.qt.nokia.com/forums/viewthread/3357

          Regards,
          Michael

          1 Reply Last reply Reply Quote 0
          • C
            chronoske last edited by

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

            1 Reply Last reply Reply Quote 0
            • C
              chronoske last edited by

              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.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post