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::setValue() replacing custom type with invalid type?
Forum Update on Tuesday, May 27th 2025

QSettings::setValue() replacing custom type with invalid type?

Scheduled Pinned Locked Moved Solved General and Desktop
qsettingsqvariantcustom data
6 Posts 3 Posters 669 Views 1 Watching
  • 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.
  • CJhaC Offline
    CJhaC Offline
    CJha
    wrote on last edited by
    #1

    Hi, in my application I am storing the settings using settings.ini file format. I have a custom data type that I register and then retrieve and store in the settings.ini file. During the startup, before the custom data type is registered using qRegisterMetaType, I call QSettings::setValue() to set a normal integer value (completely independent from the custom data type) in the settings.ini file. But doing this makes the QSettings replace all the custom types currently in the settings.ini file with an invalid QVariant type while debugging the output QVariant::load: unknown user type with name CustomDataType, is this behavior normal?

    jsulmJ JonBJ 2 Replies Last reply
    0
    • CJhaC CJha

      @JonB Thanks! I was thinking the same, but it is kind of a pity that a single key-value pair cannot be accessed without checking each entry in the .ini file, after all keys are stored as text and should be easy to filter out.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #6

      @CJha The problem is that you can't just replace something in a file if new value has different lenght than the old one. In this case you need to read the file into memory, replace the value and write it back. To read such an ini file and replace something there Qt needs to know how to interpret the data it reads.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • CJhaC CJha

        Hi, in my application I am storing the settings using settings.ini file format. I have a custom data type that I register and then retrieve and store in the settings.ini file. During the startup, before the custom data type is registered using qRegisterMetaType, I call QSettings::setValue() to set a normal integer value (completely independent from the custom data type) in the settings.ini file. But doing this makes the QSettings replace all the custom types currently in the settings.ini file with an invalid QVariant type while debugging the output QVariant::load: unknown user type with name CustomDataType, is this behavior normal?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @CJha said in QSettings::setValue() replacing custom type with invalid type?:

        is this behavior normal?

        I think so, because at that time you did not yet registered you custom type, right?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        CJhaC 1 Reply Last reply
        1
        • CJhaC CJha

          Hi, in my application I am storing the settings using settings.ini file format. I have a custom data type that I register and then retrieve and store in the settings.ini file. During the startup, before the custom data type is registered using qRegisterMetaType, I call QSettings::setValue() to set a normal integer value (completely independent from the custom data type) in the settings.ini file. But doing this makes the QSettings replace all the custom types currently in the settings.ini file with an invalid QVariant type while debugging the output QVariant::load: unknown user type with name CustomDataType, is this behavior normal?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #3

          @CJha
          Thinking aloud. In order to do any setValue() (or just value(), or any other QSettings operation) the Qt code is going to have to read the whole of the .ini file and parse it correctly. It cannot just "access a single key-value". So it seems reasonable to me that it will fall over if the file contains any unknown custom data type at that point. You really need to call any qRegisterMetaType() before you try to access anything in the .ini file, ISTM.

          CJhaC 1 Reply Last reply
          2
          • jsulmJ jsulm

            @CJha said in QSettings::setValue() replacing custom type with invalid type?:

            is this behavior normal?

            I think so, because at that time you did not yet registered you custom type, right?

            CJhaC Offline
            CJhaC Offline
            CJha
            wrote on last edited by
            #4

            @jsulm Yes, the custom data type is registered afterward when the code execution reaches that point.

            1 Reply Last reply
            0
            • JonBJ JonB

              @CJha
              Thinking aloud. In order to do any setValue() (or just value(), or any other QSettings operation) the Qt code is going to have to read the whole of the .ini file and parse it correctly. It cannot just "access a single key-value". So it seems reasonable to me that it will fall over if the file contains any unknown custom data type at that point. You really need to call any qRegisterMetaType() before you try to access anything in the .ini file, ISTM.

              CJhaC Offline
              CJhaC Offline
              CJha
              wrote on last edited by
              #5

              @JonB Thanks! I was thinking the same, but it is kind of a pity that a single key-value pair cannot be accessed without checking each entry in the .ini file, after all keys are stored as text and should be easy to filter out.

              jsulmJ 1 Reply Last reply
              0
              • CJhaC CJha

                @JonB Thanks! I was thinking the same, but it is kind of a pity that a single key-value pair cannot be accessed without checking each entry in the .ini file, after all keys are stored as text and should be easy to filter out.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @CJha The problem is that you can't just replace something in a file if new value has different lenght than the old one. In this case you need to read the file into memory, replace the value and write it back. To read such an ini file and replace something there Qt needs to know how to interpret the data it reads.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                3
                • CJhaC CJha has marked this topic as solved on

                • Login

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