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. Qt 6 way of saving a Unicode string to QSettings – Is this a bug or a feature?!
Forum Updated to NodeBB v4.3 + New Features

Qt 6 way of saving a Unicode string to QSettings – Is this a bug or a feature?!

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 588 Views 2 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.
  • l3u_L Offline
    l3u_L Offline
    l3u_
    wrote on last edited by
    #1

    Hi all :-)

    I save one single char as a symbol in a QSettings key. Apparently, the way Qt 6 saves such a string is different from Qt 5:

    The default symbol I use is QStringLiteral("\u25CF"), "BLACK CIRCLE". When I save this using Qt 5 (by using setValue(s_symbol, text)), the following appears in my config file:

    symbol=\x25cf
    

    When I build my program using Qt 6, this is – without calling the respective save method, silently! – changed to it's literal Unicode representation, and I get:

    symbol=●
    

    When using the same config again with a Qt 5 build, this is read and displayed as (using symbol = value(s_symbol, DefaultValues::symbol).toString()):

    ●
    

    (an â followed by two boxes). And again, without calling the save method, this is silently changed to

    symbol=\xe2\x97\x8f
    

    The problem is that I can't detect if the symbol is what it should be, or if it has been "messed up" by Qt 6.

    So: Is this a bug or a feature?! And if it's the latter: Is there any way to force Qt 6 to save the escaped version that can also be read by Qt 5?

    Thanks for all help!

    Cheers, Tobias!

    1 Reply Last reply
    1
    • hskoglundH Online
      hskoglundH Online
      hskoglund
      wrote on last edited by
      #2

      Hi, I had a similar problem and got around it by using toHex() and fromHex() for QSettings, e.g. setValue(s_symbol, text.toUtf8().toHex()) when saving, and using ...fromHex().fromUtf8() when reading back.

      1 Reply Last reply
      3
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Qt6 assumes that the ini-file is utf-8 encoded so a hex encoding is no longer needed. This is not backwards compatible but consistent.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        l3u_L 1 Reply Last reply
        2
        • l3u_L Offline
          l3u_L Offline
          l3u_
          wrote on last edited by
          #4

          Okay, good to know! Thanks for the clarification.

          1 Reply Last reply
          0
          • l3u_L l3u_ has marked this topic as solved on
          • Christian EhrlicherC Christian Ehrlicher

            Qt6 assumes that the ini-file is utf-8 encoded so a hex encoding is no longer needed. This is not backwards compatible but consistent.

            l3u_L Offline
            l3u_L Offline
            l3u_
            wrote on last edited by
            #5

            @Christian-Ehrlicher Oh, I just realized you said that INI files are assumed to be UTF-8 – does this mean the change does not affect Windows, where the settings are stored in the registry?

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              It should not as the registry should be unicode

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              1
              • l3u_L Offline
                l3u_L Offline
                l3u_
                wrote on last edited by
                #7

                Okay. Thanks for the info! Let's see :-)

                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