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. Linking Qt Quick with SQLite

Linking Qt Quick with SQLite

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 8.8k 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.
  • C Offline
    C Offline
    chronoske
    wrote on last edited by
    #1

    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
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      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
      0
      • M Offline
        M Offline
        mbrasser
        wrote on last edited by
        #3

        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
        0
        • C Offline
          C Offline
          chronoske
          wrote on last edited by
          #4

          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
          0
          • C Offline
            C Offline
            chronoske
            wrote on last edited by
            #5

            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
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved