Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. How to determine system encoding in Qt 6?
Forum Updated to NodeBB v4.3 + New Features

How to determine system encoding in Qt 6?

Scheduled Pinned Locked Moved Solved Qt 6
3 Posts 2 Posters 171 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.
  • T Offline
    T Offline
    theGreatWhiteShark
    wrote 25 days ago last edited by
    #1

    Previously, I could use QTextCodec::codecForLocale() to determine the local encoding in an OS-agnostic way. The main use case was to include it in the application log. At least two times this was key to reproduce an user issue concerning file import. But for Qt6 QTextCodec is only available as a Qt5 compatibility feature.

    Is there a new, Qt 6 native way to determine the system's local encoding? I couldn't find it in the docs (or other forum posts)

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Axel Spoerl
      Moderators
      wrote 25 days ago last edited by
      #2

      I'd do the following:

      const QLocale locale = QLocale::system();
      const auto encoding = QStringConverter::encodingForName(locale.name().toUtf8());
      

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      2
      • T Offline
        T Offline
        theGreatWhiteShark
        wrote 24 days ago last edited by
        #3

        Thanks a lot!

        1 Reply Last reply
        0
        • T theGreatWhiteShark has marked this topic as solved 24 days ago

        1/3

        11 May 2025, 11:49

        • Login

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