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
Forum Updated to NodeBB v4.3 + New Features

QLocale doesn't match system locale

Scheduled Pinned Locked Moved Solved General and Desktop
qlocalelocaleqdatetime
4 Posts 2 Posters 706 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
    TheEnigmist
    wrote on 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
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on 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
      0
      • SGaistS SGaist

        Hi,

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

        T Offline
        T Offline
        TheEnigmist
        wrote on 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 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

          • Login

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