Data file
-
QtQuick 2? Use the QtQuick.LocalStorage singleton type.
Cheers,
Chris. -
Of course there is. Offline local storage using MySQL. Grab to following code and add it to a javascript file.
storage.js
@
//
/ Key Value store (mostly used for settings storage) /
///** Set value to storage */
function setKeyValue(key, value) {
var db = openDatabaseSync("YOUR_APP_NAME", "1.0", "Description", 10);db.transaction(function(tx) { tx.executeSql('CREATE TABLE IF NOT EXISTS ' + 'KeyValueStorage(keyName TEXT, textValue TEXT)'); var rs = tx.executeSql("SELECT textValue FROM KeyValueStorage WHERE keyName = \"" + key + "\""); var sql = ""; if(rs.rows.length>0) { sql = "UPDATE KeyValueStorage SET textValue = \"" + value + "\" WHERE keyName = \"" + key + "\""; } else { sql = "INSERT INTO KeyValueStorage(textValue, keyName) VALUES (\"" + value + "\",\"" + key + "\")"; } tx.executeSql(sql); });
}
/** Get value from storage */
function getKeyValue(key) {
var value;
var db = openDatabaseSync("YOUR_APP_NAME", "1.0", "Description", 10);
db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS KeyValueStorage(keyName TEXT, textValue TEXT)');
var result = "";
var rs = tx.executeSql("SELECT textValue FROM KeyValueStorage WHERE keyName = "" + key + """);
for (var i = 0; i < rs.rows.length; i++) {
result = rs.rows.item(i).textValue;
value = result;
//console.log("---, " + value);
}
if(rs.rows.length===0) {
value = "0";
//console.log("---, " + value);
}
});
return value;
}
@So this is a simple singleton key-value storage. To use it in a qml file just write the following:
@
import QtQuick 1.1
import "storage.js" as Storage...
Storage.setKeyValue("ip", "0.0.0.0");
...
@Regards.
-
Wait a minute, what do you mean "where is the file location" ?
Why do you care where is the file stored since the functionality is working and you are either way going to access it only through your program?
Any way, to answer your question, there is a MySQL file created in the executable's folder in binary format that holds the data of the local database that gets created when using the code that i posted above.
-
When you write you wanted a binary file, that implies to me, and I think favoritas37 that you do not ever want to use it as a document that you can email a friend.
The only time you want to store something in binary form is when you just want to use it to remember the data between times you run the app.So thats why the mysql answer was given, its a simple and effective way to do it :)
If your needs are different than that, please explain, maybe there is a better solution!
-
Hello Thomas,
indeed this is what i wanted to say.
Thank you :)