[SOLVED]Working with iOS Settings.bundle preferences



  • Can someone tell me how to accomplish the following two tasks for iOS apps in the Qt context?

    1. Read user preference from the root.plist file in the Settings.bundle of my app
    2. Register default values

    I appreciate any help!



  • 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


  • Lifetime Qt Champion

    Hi,

    The question might seem silly but are you sure you are looking in the right place for the Settings.bundle folder ?



  • I verified that the output from:

    QGuiApplication::applicationDirPath()+ "/Settings.bundle/Root.plist"

    leads to the correct location. I put a qDebug() statement to the console to display the path and then followed it from a terminal window


  • Lifetime Qt Champion

    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>
    

  • Lifetime Qt Champion

    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 That did the trick. Thank you very much!



  • This post is deleted!


  • @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?


  • Lifetime Qt Champion

    I may be wrong but in your example, engineHostname is the value for the key "Key". Shouldn't engineHostname be the key ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.