Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I'm working on a small game and i'd like to know how can i write/read a user settings file in ubuntu touch?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

You have a couple of options, you can use a LocalStorage to create a local sqlite database to keep your settings in. Or you can use the (still very alpha-stage) U1DB component, which will still use a local sqlite database, but also allows you to sync your settings database between the user's different machines/devices.

share|improve this answer
the U1DB component seems to be the best option, thanks for the info. –  Hairo Mar 30 '13 at 15:19
This answer has an example of using LocalStorage to save user settings:… –  andrewsomething Oct 7 '13 at 22:12
The LocalStorage link is broken. I guess it moved to… –  int_ua Apr 13 '14 at 14:59
Also, I haven't found a way to edit settings in U1DB –  int_ua Apr 13 '14 at 15:00

LocalStorage example


function getDatabase() {
     return LocalStorage.openDatabaseSync("appname", "0.1", "SettingsDatabase", 100);

function set(setting, value) {
   var db = getDatabase();
   var res = "";
   db.transaction(function(tx) {
        tx.executeSql('CREATE TABLE IF NOT EXISTS settings(setting TEXT UNIQUE, value TEXT)');
        var rs = tx.executeSql('INSERT OR REPLACE INTO settings VALUES (?,?);', [setting,value]);
              if (rs.rowsAffected > 0) {
                res = "OK";
              } else {
                res = "Error";
  return res;

function get(setting, default_value) {
   var db = getDatabase();
   var res="";
   try {
       db.transaction(function(tx) {
         var rs = tx.executeSql('SELECT value FROM settings WHERE setting=?;', [setting]);
         if (rs.rows.length > 0) {
              res = rs.rows.item(0).value;
         } else {
             res = default_value;
   } catch (err) {
       //console.log("Database " + err);
       res = default_value;
  return res

QML imports

import QtQuick.LocalStorage 2.0
import "storage.js" as Settings

QML usage


I've used this example but had to modify it.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.