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. QLocale doesn't match system locale
QtWS25 Last Chance

QLocale doesn't match system locale

Scheduled Pinned Locked Moved Solved General and Desktop
qlocalelocaleqdatetime
4 Posts 2 Posters 679 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.
  • T Offline
    T Offline
    TheEnigmist
    wrote on 22 Mar 2022, 22:22 last edited by
    #1

    I'm using Qt 6.2.1 on Windows 11 with a system locale different from en_US but whatever project I create (Window, Console) if I use a simple code like:

    qInfo().nospace() << QDateTime::currentDateTime().toString("dd MMMM yyyy hh:mm:ss.zzz");
    

    It prints the date in english locale

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 23 Mar 2022, 21:01 last edited by
      #2

      Hi,

      What is your locale ?
      What do you get ?
      What do you expect ?

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

      T 1 Reply Last reply 25 Mar 2022, 22:42
      0
      • S SGaist
        23 Mar 2022, 21:01

        Hi,

        What is your locale ?
        What do you get ?
        What do you expect ?

        T Offline
        T Offline
        TheEnigmist
        wrote on 25 Mar 2022, 22:42 last edited by
        #3

        @SGaist Hi,
        My system locale is it_IT
        a64f1181-a368-4d53-8306-146ba383e420-image.png
        As you can see currentDateTime().toString() gives me string in en_US
        I expect to get that string in my system locale

        1 Reply Last reply
        0
        • T Offline
          T Offline
          TheEnigmist
          wrote on 26 Mar 2022, 19:37 last edited by TheEnigmist
          #4

          I found the error. From docs here: https://doc.qt.io/qt-6/qdatetime.html#toString it is reported

          Note: Day and month names as well as AM/PM indication are given in English (C locale). If localized month and day names and localized forms of AM/PM are used, use QLocale::system().toDateTime().
          

          Correct way to use system locale or a desired locale is

          qInfo().nospace() << QLocale::system().toString(QDateTime::currentDateTime(), "dd MMMM yyyy hh:mm:ss.zzz");
          
          1 Reply Last reply
          2

          3/4

          25 Mar 2022, 22:42

          • Login

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