Store Data Persistent

In order to store data persistent bewteen app runs, you can make use of different database features.

Key/Value Storage with the App Settings

You can store simple key/value pairs using the App::settings property. If you format the value with JSON, you can also use this to store more complex data in a very easy way.

 import VPlayApps 1.0
 import QtQuick 2.5

 App {
   id: app
   // this property holds how often the app was started
   property int numberAppStarts

   Component.onCompleted: {
     // this code reads the numberAppStarts value from the database

     // getValue() returns undefined, if no setting for this key is found, so when this is the first start of the app
     var tempNumberAppStarts = app.settings.getValue("numberAppStarts")
     if(tempNumberAppStarts === undefined)
       tempNumberAppStarts = 1
     else
       tempNumberAppStarts++

     app.settings.setValue("numberAppStarts", tempNumberAppStarts)
     numberAppStarts = tempNumberAppStarts
   }

   NavigationStack {

     Page {
       title: "Settings"

       AppText {
         anchors.centerIn: parent
         text: "App starts: " + numberAppStarts
       }
     }
   }
 }

Key/Value Storate with QML Storage

This Storage component is used internally for the App settings from the example above. You can also use it as standalone component.

 import VPlay 2.0  // The Storage type requires to import VPlay 2.0
 import VPlayApps 1.0
 import QtQuick 2.5

 App {
   id: app
   // this property holds how often the app was started
   property int numberAppStarts

   Component.onCompleted: {
     // this code reads the numberAppStarts value from the database

     // getValue() returns undefined, if no setting for this key is found, so when this is the first start of the app
     var tempNumberAppStarts = storage.getValue("numberAppStarts")
     if(tempNumberAppStarts === undefined)
       tempNumberAppStarts = 1
     else
       tempNumberAppStarts++

     storage.setValue("numberAppStarts", tempNumberAppStarts)
     numberAppStarts = tempNumberAppStarts
   }

   Storage {
     id: storage
   }

   NavigationStack {

     Page {
       title: "Settings"

       AppText {
         anchors.centerIn: parent
         text: "App starts: " + numberAppStarts
       }
     }
   }
 }

Key/Value Storage with QML Settings

This Settings component pretty similar to the App settings, however the usage is a bit different. It uses the defined properties as keys, to store and retrieve the values.

Cloud Key/Value Storage

The WebStorage component offers storing of Key/Value pairs in the cloud.

SQLite Database to Store Data

You can access a local SQLite Database using the Qt Quick Local Storage QML Types

Store Data with Google Firebase

You can also use the Google Firebase Database plugin to store and distribute data.

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support