Data file
-
wrote on 31 Jan 2013, 10:24 last edited by
I am working on Network Configuration app, so i want the data entered by the user to be stored in a file in binary format. Please help
-
wrote on 31 Jan 2013, 10:40 last edited by
Do you need pure qml solution?
-
wrote on 31 Jan 2013, 10:50 last edited by
Yes. I would be developing it in QML.
-
wrote on 1 Feb 2013, 00:18 last edited by
QtQuick 2? Use the QtQuick.LocalStorage singleton type.
Cheers,
Chris. -
wrote on 3 Feb 2013, 08:59 last edited by
I m currently using QtQuick 1.1. Isn't there something similar in it?
-
wrote on 3 Feb 2013, 10:41 last edited by
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.
-
wrote on 3 Feb 2013, 19:40 last edited by
Thanks a lot. I tried it, but where is the file location. I could not find
-
wrote on 9 Feb 2013, 06:34 last edited by
I managed to get a file using a Qfile. Now I want to connect the value entered by the user in the qml file to a variable whose value can be stored in the file through C++.
-
wrote on 9 Feb 2013, 15:21 last edited by
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.
-
wrote on 9 Feb 2013, 17:05 last edited by
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!
-
wrote on 9 Feb 2013, 17:40 last edited by
Hello Thomas,
indeed this is what i wanted to say.
Thank you :)
-
wrote on 11 Feb 2013, 09:34 last edited by
Hi favoritas37
I just wanted to check whether the code was working properly or not. Thanks for your help -
wrote on 12 Feb 2013, 11:48 last edited by
I would be running this app on embedded platform eventually, so will the java code make it slow
-
wrote on 12 Feb 2013, 13:36 last edited by
Qt and/or QML is not using Java.
6/14