Hi all

This morning on the train on the way to work I tried the following to change the location of the offlineStorage DB:

The c++ main function of the demo app CreateDBQt5 now looks like this:

int main(int argc, char *argv[])
{
    QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
    QScopedPointer<QQuickView> view(SailfishApp::createView());
qDebug() << "offlineStoragPath orig: " << view->engine()->offlineStoragePath(); view->engine()->setOfflineStoragePath(QString("/home/nemo/.local/share/landed25_QT5/QML/OfflineStorage" )); qDebug() << "offlineStoragPath new: " << view->engine()->offlineStoragePath();
    view->setSource(SailfishApp::pathTo("qml/CreateDBQt5.qml"));
    view->show();
    view->showFullScreen();
    return app->exec();
}

This gives the following Application Output:
[D] main:42 - offlineStoragPath orig: "/home/nemo/.local/share/CreateDBQt5/QML/OfflineStorage" [D] main:44 - offlineStoragPath new: "/home/nemo/.local/share/landed25_QT5/QML/OfflineStorage"

The database is indeed created in /home/nemo/.local/share/landed25_QT5/QML/OfflineStorage", and is accessible to the app landed25_QT5

Note the order of the view->engine()->setOfflineStoragePath... and view->setSource... calls is crucial. If the setSource comes first, then the QML is initiated before the storagePath is changed!

In my next experiment I will try to change the storageLocation to something like QStandardPaths::GenericDataLocation.

The question on harbour acceptability remains ...

Chris



----- Weitergeleitete Nachricht von christopher.l...@thurweb.ch -----
     Datum: Wed, 15 Jan 2014 22:34:40 +0100
       Von: christopher.l...@thurweb.ch
Antwort an: "Sailfish OS Developers" <devel@lists.sailfishos.org>
Betreff: [SailfishDevel] Sharing a common OfflineStorage DB between multiple Sailfish apps.
        An: "Sailfish OS Developers" <devel@lists.sailfishos.org>

Hi all

Is it possible to steer where a QML application stores its OfflineStorage Database?

I have a family of applications that share a common OfflineStorage Database. This works well on Harmattan, and on the early Sailfish Alphas without me having had to do anything special at all.

In the early Sailfish Alphas OfflineStorage DBs were stored in a common location, and thus could be easily shared.
/home/nemo/.local/share/data/QML/OfflineStorage/Databases

Now on the real Jolla, I find that the standard DB storage location has changed, and DBs are now put in a subdirectory of the application's installation folder. e.g.

/home/nemo/.local/share/landed25_QT5/QML/OfflineStorage
/home/nemo/.local/share/CreateDBQt5/QML/OfflineStorage

This means without some magic, Sailfish apps can no longer share DBs.

In C++ there is a property offlineStoragePath, and a setter method setOfflineStoragePath().

http://qt-project.org/doc/qt-5/qqmlengine.html#offlineStoragePath-prop

I might be able to use this to change the location of the DB, e.g to one of the Qt StandardLocations:

http://qt-project.org/doc/qt-5.0/qtcore/qstandardpaths.html#StandardLocation-enum

But setOfflineStoragePath() appears not to be directly available to QML.

http://stackoverflow.com/questions/14209585/how-to-set-custom-offline-storage-path-from-javascript-in-qtquick

So I guess I could call setOfflineStoragePath in each apps' main cpp file.

Or maybe I could even write a declarative plugin to expose setOfflineStoragepath to QML, but that is probably overkill as it would instantiate QQmlEngine - just t o set a path.

Or is there a better way? Are there any Harbour entry considerations to an app creating / accessing a DB somewhere other than in its own folder?

Thanks

Chris

_______________________________________________
SailfishOS.org Devel mailing list


----- Ende der weitergeleiteten Nachricht -----


_______________________________________________
SailfishOS.org Devel mailing list

Reply via email to