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. Use an existing SQLite DB with QML

Use an existing SQLite DB with QML

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 3 Posters 11.7k Views
  • 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.
  • A Offline
    A Offline
    arno5m
    wrote on last edited by
    #1

    Hi,
    I want to be able to browse an existing SQLite database file from the OfflineStorage qml sample.

    I've ran and noticed that QMLViewer create Db in the directory (windows):
    ~\Local Settings\Application Data\Nokia\QtQmlViewer\QML\OfflineStorage\Databases
    for each data base it creates XXX.sqlite file, XXX.ini file (with openDatabaseSync() parameters), and a XXX directory. Where XXX is something like to "fcc39b3050a2d659cf2c48d5a71fd11d" (headhache ;-)).
    I've made this simple test: copy my file (mydb.sqlite) in same DB directory, create the mydb.ini file with "MyDB" as DB name, and create empty mydb directory. Then quit/restart QtCreator (perhaps it hold a db file cross reference table, who now ?)

    When I try to openDatabaseSync("MyDB", ...) .... then mydb file is not loaded, in place QMLViewer prefer to create en newly DB.

    Where is my mistake ?

    1 Reply Last reply
    0
    • 2 Offline
      2 Offline
      2beers
      wrote on last edited by
      #2

      not sure exactly but if you restart the qt creator and run again the qml file again maybe the directory has been changed from “fcc39b3050a2d659cf2c48d5a71fd11d” to another value. did you check to see if another directory has been made?

      I think you should create a new QT(not QML) project and use QDeclarativeView to load the qml file and copy your database in you project directory and see if it works. I played a few weeks ago like this and it worked, but I didn't give much importance at that moment.

      Hope it helps in any way

      1 Reply Last reply
      0
      • A Offline
        A Offline
        arno5m
        wrote on last edited by
        #3

        Thanks for your reply.
        QMLViewer create the new DB only once then it always use this one and never my own .... like if there are a database dictionnary file elsewhere (registery?) whereas I was simply thinking QMLViewer load all .ini in this directory to discover existing database.
        I'm close to be sure that quit/restart QtCreator have no effect on how QMLViewer handle new database.

        In other hand, this is my first tests learning and using QML, this is just an evaluation of QtQuick, and I don't want, yet, spend time in C++ compiling. Because I develop somtimes on windows, sometimes on mac OSX.
        But if it's the only way to do this ... time to swim ! ;-).

        1 Reply Last reply
        0
        • B Offline
          B Offline
          blam
          wrote on last edited by
          #4

          The file name is a MD5 hash of the database name.

          E.g. if your database is named "mydb", if you run Qt.md5("mydb") the result is e04d88072f90f86a07481418b8ff4b6b. Use this to name your .sqlite, .ini and folder in the Databases directory and then openDatabaseSync() will open the existing database correctly.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            arno5m
            wrote on last edited by
            #5

            Thanks you blam, that is exactly what i need to go further on my prototype.

            As I can see all the directory associated to databases are empty, do you known what is the purpose of those directories ?

            1 Reply Last reply
            0
            • B Offline
              B Offline
              blam
              wrote on last edited by
              #6

              Looks like the directories are not required. I've filed http://bugreports.qt.nokia.com/browse/QTBUG-15909 so they aren't created in the first place.

              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