Qt Quick Local Storage Export / Import Database
-
Hello,
I'm using QML local storage in my application. I'd like my user to be able to export and import the database file for backup and migration. Is this possible using the QML interface or do I need to rewrite my DB bindings in C++?
Thanks,
Charles -
Hi,
Can you explain what do you mean by import and export from your application point of view ?
IMO, backup and migration must be done through c++ -
Hi,
QML Local Storage creates an SQLLite database file internally. Is there a way allow the user to copy that file and replace it. To export (save database file as), and to import (replace current database with saved file). I know the file operations will be done in C++. I'm wondering if I can continue to use QML Local Storage and allow import/export of the database file?
Thanks,
Charles -
There's no way to copy and replace file from QML. Do those from C++ side. You can use those "QFile::exists":http://qt-project.org/doc/qt-5/qfile.html#exists-2, QFile::copy and QFile::remove static functions.
Yes sure you use QML local storage. After all it would be a db file physically present on the system. Do the file operations from c++ before your QML loads or as per your requirement.
-
Thanks very much. This all makes sense.
However, how do I get the filepath of the DB file? I'm targeting Win32 / OSX / Ubuntu desktops.
-
The file is actually created in a standard Data location of your system and that too inside the <your ApplicationName> folder.
You can use "offlineStoragePath":http://qt-project.org/doc/qt-5/qqmlengine.html#offlineStoragePath-prop to get the path of DB.