I've hit a snag in development regarding saving application settings on Android.
Currently I'm using the following:
QSettings *settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "Company","Application-Name", 0);
To copy to clipboard, switch view to plain text mode
This works perfectly on Windows, Linux, MacOS, iOS, but it does not work on Android. After searching around here and a few other places (stackoverflow), I see most people using something similar to the following to declare the exact file name/path:
QString m_path
= QStandardPaths
::writableLocation(QStandardPaths
::ConfigLocation);
QString m_settingsfile
= m_path
+ "/" + m_filename;
QString m_path = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
QString m_filename = "config.ini";
QString m_settingsfile = m_path + "/" + m_filename;
QSettings *settings = new QSettings(m_settingsfile, QSettings::IniFormat);
To copy to clipboard, switch view to plain text mode
However this does not work for me either.
I get no errors on compilation on any system (including android), and debugging shows no errors. I assume the problem is a permissions issue, but I can't seem to track it down without any errors anywhere.
I have the following in my AndroidManifest.xml
<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="23"/>
<uses-permission android:name="android.permission.WRITE_SECURE_SETT INGS"/>
<uses-permission android:name="android.permission.PERSISTENT_ACTIVI TY"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_ST ORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STO RAGE"/>
<uses-permission android:name="android.permission.WRITE_PROFILE"/>
Within my application I'm saving information with something like:
void mainWindow::addInfo(){
if(!INFO.hasLoaded()){
//New settings data - need to prompt for a password
if(pass.isEmpty()){ return; } //cancelled
while(chk!=pass){
if(chk.isEmpty()){ return; } //cancelled
}
}
Host host(ui->line_ip->text(), ui->line_desc->text(), ui->line_name->text(), ui->line_field->text());
HOSTS << host;
if( !HOSTS.saveHostInformation(settings, pass) ){
//Could not save information
QMessageBox::warning(this, tr
("Error"), tr
("Could not save host information to disk") );
}
updateInfo();
ui->info_add->setVisible(false);
}
void mainWindow::addInfo(){
QString pass;
if(!INFO.hasLoaded()){
//New settings data - need to prompt for a password
pass = QInputDialog::getText(this, tr("Create New Password"), tr("Password:"), QLineEdit::Password);
if(pass.isEmpty()){ return; } //cancelled
QString chk;
while(chk!=pass){
chk = QInputDialog::getText(this, tr("Verify New Password"), tr("Password:"), QLineEdit::Password);
if(chk.isEmpty()){ return; } //cancelled
}
}
Host host(ui->line_ip->text(), ui->line_desc->text(), ui->line_name->text(), ui->line_field->text());
HOSTS << host;
if( !HOSTS.saveHostInformation(settings, pass) ){
//Could not save information
QMessageBox::warning(this, tr("Error"), tr("Could not save host information to disk") );
}
updateInfo();
ui->info_add->setVisible(false);
}
To copy to clipboard, switch view to plain text mode
I know my overall code is fine, because it works on every platform other than Android. My issue is with something android specific, but I haven't been able to track it down. Probably because it's something simple and I keep overlooking it.
Can someone point me in the right direction?
Bookmarks