[SOLVED]Working with iOS Settings.bundle preferences
-
Here's what I have so far, but it's not working..
QSettings settings(QGuiApplication::applicationDirPath() + "/Settings.bundle/Root.plist", QSettings::NativeFormat, &app); if (settings.contains("Title")) { qDebug() << "FOUND TITLE"; }
The qDebug() statement is never getting hit
-
Hi,
The question might seem silly but are you sure you are looking in the right place for the Settings.bundle folder ?
-
Can you share the content of Root.plist ?
-
Sure! Here it is:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>PreferenceSpecifiers</key> <array> <dict> <key>Type</key> <string>PSTextFieldSpecifier</string> <key>Title</key> <string>TAP Engine Hostname: </string> <key>DefaultValue</key> <string>localhost</string> <key>Key</key> <string>engineHostname</string> </dict> </array> <key>StringsTable</key> <string>Root</string> </dict> </plist>
-
Ok, Title is a key in a dict in an array so you have to retrieve following that way (long way):
QVariantList preferenceSpecifiers = settings.value("PreferenceSpecifiers").toList(); QVariant preferenceSpecifier = preferenceSpecifiers.first(); QVariantMap preferenceSpecifierContent = preferenceSpecifier.toMap(); // Now you can retrieve Title and the rest
Short version:
QString title = settings.value("PreferenceSpecifiers").toList().first().toMap().value("Title").toString();
-
Ok, Title is a key in a dict in an array so you have to retrieve following that way (long way):
QVariantList preferenceSpecifiers = settings.value("PreferenceSpecifiers").toList(); QVariant preferenceSpecifier = preferenceSpecifiers.first(); QVariantMap preferenceSpecifierContent = preferenceSpecifier.toMap(); // Now you can retrieve Title and the rest
Short version:
QString title = settings.value("PreferenceSpecifiers").toList().first().toMap().value("Title").toString();
-
Ok, Title is a key in a dict in an array so you have to retrieve following that way (long way):
QVariantList preferenceSpecifiers = settings.value("PreferenceSpecifiers").toList(); QVariant preferenceSpecifier = preferenceSpecifiers.first(); QVariantMap preferenceSpecifierContent = preferenceSpecifier.toMap(); // Now you can retrieve Title and the rest
Short version:
QString title = settings.value("PreferenceSpecifiers").toList().first().toMap().value("Title").toString();
-
Ok, Title is a key in a dict in an array so you have to retrieve following that way (long way):
QVariantList preferenceSpecifiers = settings.value("PreferenceSpecifiers").toList(); QVariant preferenceSpecifier = preferenceSpecifiers.first(); QVariantMap preferenceSpecifierContent = preferenceSpecifier.toMap(); // Now you can retrieve Title and the rest
Short version:
QString title = settings.value("PreferenceSpecifiers").toList().first().toMap().value("Title").toString();
@SGaist Ok, it seems I have hit a wall. I don't know how to look up the value of "engineHostname" since its not a key. Just reading the .plist isn't enough since the actual values don't seem to be stored there. For example, I installed the app on my iPad and set the Engine Hostname to "Joe" in the Settings app. The thing is, I don't know how to get that value back. The .plist does not seem to store this value. It's somewhere else and I can't seem to figure out a "Qt way" to get to it. Do I have to add a .mm file to my project and make calls through NSUserDefaults?
-
I may be wrong but in your example, engineHostname is the value for the key "Key". Shouldn't engineHostname be the key ?