Solved Saving dial value
-
ok, but how to you save it to file ? and load it from file again?
If you dont load the old value from a file, it will
just have some random value when you start again. -
@mrjj
yow want to know whether i use QFile or something same to store the value or not ? if so , i dont use anything like that. İ just define save variable in second.h module with default value "0". -
@rapid84
Ok. but it cannot remember values from run to run, unless you save it in a file.
I do wonder why it has that high value if you set it to 0. -
if i define with "0" i got only "0" value, but when i define without any default, i got some value like "199922356" , so it is just misunderstanding. anyway, then i have to use QFile, crate a file and save the value to it, and load the save value from a file ?
-
@rapid84
If you dont define any default value, it will just have random value as it just uses
what ever is in that memory location.Yes, to keep it for later runs, you must save it to file. QFile is fine to use.
You can also have a look at QSettings.
http://doc.qt.io/qt-5/qsettings.html
Its ment for saving such values.its easy to use
//load QSettings settings("settingName"); int aValue=settings.value("aKey").toInt(); //write QSettings settings("settingName"); int somevalue=yoursave; settings.setValue("aKey",somevalue);
-
"aKey" is a mandatory paramater ? and the reference mentions that:
When creating a QSettings object, you must pass the name of your company or organization as well as the name of your application. For example, if your product is called Star Runner and your company is called MySoft, you would construct the QSettings object as follows: QSettings settings("MySoft", "Star Runner");
Is this mandatory ? what if , if i dont have any company ? :)
-
@rapid84
hi
the akey is the name of the value. It saves to registry so that why it needs a name
For you , it could be slidervalue or something that explains what u save.You can use anything u like for company. Its also because its store in registry.
So just use some name u like that IS not a real company. :) -
For loading i use;
QSettings settings("settingName"); int aValue=settings.value("aKey").toInt(); int aValue2=settings.value("aKey2").toInt(); ui->dial->setValue(aValue); ui->dial_2->setValue(aValue2);
and for saving i use
QSettings settings("settingName"); int somevalue = ui->dial->value(); int somevalue2 = ui->dial_2->value(); settings.setValue("aKey",somevalue); settings.setValue("aKey2",somevalue2);
These work for me , thanks for help. by the way, in a debian OS , where do it save ( in which directory)?
-
Hi
That is good question :)
try
qDebug() << settings.fileName(); -
If I may suggest one improvement is to use a better name than
"aKey" and "aKey2"
Maybe Dial1Value and Dial2Value -
when i click the close button, while it is saving data , it waits sometime and close with a 1-2 seconds delay. Is this normal ?
-
@rapid84
Normally it saves really fast so i never noticed it. -
@mrjj
on raspbian sometimes it takes up to 5 -6 seconds to store the data. i have tested it, maybe i will need to use QFile. -
@rapid84
ok. thats pretty long.
It must have a reason.
QFile should be faster. -
Hi,
You shouldn't need to but you can try adding a call to sync in order to flush the content of your settings to the disk.
-