Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [SOLVED]Working with iOS Settings.bundle preferences
QtWS25 Last Chance

[SOLVED]Working with iOS Settings.bundle preferences

Scheduled Pinned Locked Moved Mobile and Embedded
ios files sandbios
11 Posts 2 Posters 3.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DRoscoe
    wrote on last edited by DRoscoe
    #1

    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!

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DRoscoe
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DRoscoe
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Can you share the content of Root.plist ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DRoscoe
              wrote on last edited by
              #6

              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>
              
              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                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();

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                D 3 Replies Last reply
                1
                • SGaistS SGaist

                  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();

                  D Offline
                  D Offline
                  DRoscoe
                  wrote on last edited by
                  #8

                  @SGaist That did the trick. Thank you very much!

                  1 Reply Last reply
                  0
                  • SGaistS SGaist

                    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();

                    D Offline
                    D Offline
                    DRoscoe
                    wrote on last edited by DRoscoe
                    #9
                    This post is deleted!
                    1 Reply Last reply
                    0
                    • SGaistS SGaist

                      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();

                      D Offline
                      D Offline
                      DRoscoe
                      wrote on last edited by
                      #10

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

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

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

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved