I want to save some user credentials in my qt application that runs on Android. I use QSettings for this like so:
QString appPath = QCoreApplication::applicationDirPath()+QLatin1Char('/');
set = new QSettings(appPath+"test",
QSettings::NativeFormat);
set->setValue ( "user/username", "NameOfTheUser" );
set->setValue ( "user/password", "UserPassword" );
set->sync();
I restart the app and inside an initialize() method I have:
QString username(set->value("user/username",
( QVariant ) tr ( "defaultUser" ) ).toString());
QString password(set->value("user/password",
( QVariant ) tr ( "defaultPass" ) ).toString());
The username and password vars are not read from the QSettings.
The same code is working on Windows.
Thank you
I also ran into similar problem and found out that 2 things should be done:
So on Windows I had this working:
QSettings settings("settings.ini", QSettings::IniFormat);
settings.setValue(GRID_ENABLED, enabled);
On Android I have to use the following code:
QSettings settings("/sdcard/settings.ini", QSettings::NativeFormat); //can be IniFormat, no difference
settings.setValue(GRID_ENABLED, enabled);
settings.sync();
Probably using "sdcard" is not good enough and you should use other directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With