Exemplo de LocalStorage
storage.js
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
}
Importações QML
import QtQuick.LocalStorage 2.0
import "storage.js" as Settings
Uso de QML
Settings.get("setting_name",8)
Settings.set("setting_name", itemid.property)
Eu usei este exemplo , mas tive que modificá-lo.