Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSettings on macOS has unexpected flattening of arrays and groups

QSettings on macOS has unexpected flattening of arrays and groups

Scheduled Pinned Locked Moved Solved General and Desktop
qsettingsmacosx
5 Posts 2 Posters 632 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.
  • V Offline
    V Offline
    vic.ju
    wrote on 25 Aug 2020, 07:18 last edited by
    #1

    Good morning,

    I encountered a strange behaviour on macOS when using the QSettings. When data is stored with the beginGroup() or beginWriteArray() isn't it intended to create a nested structure like

    root
      |
      |--- Array
      |     |
      |     |--- Index
      |           |
      |           |--- Value1
      |           |--- Value2
      |
      |--- Group
            |
            |--- Value1
            |--- Value2
    

    Instead it creates the keys flattened as children of the root:

    root
      |
      |--- Array.Index.Value1
      |--- Array.Index.Value2
      |--- Group.Value1
      |--- Group.Value2
    

    Is this intended behaviour? The underlying CFPreferences API should be capable of building correct parent-child structures.

    J 1 Reply Last reply 25 Aug 2020, 07:28
    0
    • V vic.ju
      25 Aug 2020, 07:18

      Good morning,

      I encountered a strange behaviour on macOS when using the QSettings. When data is stored with the beginGroup() or beginWriteArray() isn't it intended to create a nested structure like

      root
        |
        |--- Array
        |     |
        |     |--- Index
        |           |
        |           |--- Value1
        |           |--- Value2
        |
        |--- Group
              |
              |--- Value1
              |--- Value2
      

      Instead it creates the keys flattened as children of the root:

      root
        |
        |--- Array.Index.Value1
        |--- Array.Index.Value2
        |--- Group.Value1
        |--- Group.Value2
      

      Is this intended behaviour? The underlying CFPreferences API should be capable of building correct parent-child structures.

      J Offline
      J Offline
      JonB
      wrote on 25 Aug 2020, 07:28 last edited by JonB
      #2

      @vic-ju
      I'm not sure if this has any relevance to MacOS. In QSettings output groups/arrays always produce "flat" keys, with a counting number for the index. The reason is that that the Windows .ini file format has no "nested structure", it is a file of key=value format, with (optional) occasional (single-level) [Section] lines to divide into sections.

      Under Windows/Linux I believe it stores group/array elements like element\index=value or element/index=value where you show the separator as .; but that's an internal detail.

      Why did you expect otherwise? The only guarantee of the QSettings output is that code should be able to read it back to produce the same data as was used to create it. It is not guaranteed to be "human readable". Under Windows it does not even promise to match expectations of other .ini files and so be compatible with them, only that QSettings can be used to write & read its own files.

      I don't know anything about "underlying CFPreferences API".

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vic.ju
        wrote on 25 Aug 2020, 08:24 last edited by
        #3

        @JonB
        On windows the QSettings values are stored in the Registry and as I just have seen the nested values are stored as a binary. Though you are right, I just expected it to use the native api calls properly because it can.

        J 1 Reply Last reply 25 Aug 2020, 08:33
        0
        • V vic.ju
          25 Aug 2020, 08:24

          @JonB
          On windows the QSettings values are stored in the Registry and as I just have seen the nested values are stored as a binary. Though you are right, I just expected it to use the native api calls properly because it can.

          J Offline
          J Offline
          JonB
          wrote on 25 Aug 2020, 08:33 last edited by JonB
          #4

          @vic-ju

          On windows the QSettings values are stored in the Registry

          No, not necessarily!

          QSettings is an abstraction around these technologies, enabling you to save and restore application settings in a portable manner.

          See https://doc.qt.io/qt-5/qsettings.html#Format-enum and the various overloads of QSettings() which allow programmer to choose how/where the settings are actually stored. Also see https://doc.qt.io/qt-5/qsettings.html#section-and-key-syntax and https://doc.qt.io/qt-5/qsettings.html#platform-specific-notes, etc.

          In previous discussions of this topic, the best we have come up with is: you can assume that settings saved from QSettings will be readable back via QSettings. Any further assumptions --- e.g. QSettings will be able to read files/settings created outside of QSettings, or vice versa --- are "unwarranted": they may work, or may work sometimes, or may not.

          1 Reply Last reply
          1
          • V Offline
            V Offline
            vic.ju
            wrote on 25 Aug 2020, 08:46 last edited by
            #5

            So that means that the custom 'style' is intentional. That answers my question.

            Thanks for your answer!

            1 Reply Last reply
            0

            1/5

            25 Aug 2020, 07:18

            • Login

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