我想在运行在 Android 上的 qt 应用程序中保存一些用户凭据。我像这样使用 QSettings :
QString appPath = QCoreApplication::applicationDirPath()+QLatin1Char('/');
set = new QSettings(appPath+"test",
QSettings::NativeFormat);
set->setValue ( "user/username", "NameOfTheUser" );
set->setValue ( "user/password", "UserPassword" );
set->sync();
我重新启动应用程序并在 initialize() 方法中拥有:
QString username(set->value("user/username",
( QVariant ) tr ( "defaultUser" ) ).toString());
QString password(set->value("user/password",
( QVariant ) tr ( "defaultPass" ) ).toString());
用户名和密码变量不是从 QSettings 中读取的。
相同的代码在 Windows 上运行。
谢谢