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::system().script() always returning 0 on Windows
QtWS25 Last Chance

QLocale::system().script() always returning 0 on Windows

Scheduled Pinned Locked Moved General and Desktop
qlocalelocalescriptwindowsbcp47name
3 Posts 2 Posters 1.6k 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.
  • D Offline
    D Offline
    djtrifun
    wrote on 7 Jun 2015, 08:22 last edited by djtrifun 6 Jul 2015, 19:11
    #1

    I am trying to distinguish between Serbian Latin and Serbian Cyrillic locales on Windows, but QLocale::system().script() seem to always return 0 (QLocale::Script::AnyScript).

    I tried on Windows 7 and Windows 8.1, with Qt 5.4.2 as well as Qt 4.8.5, always with the same result. I also tried with other multi-script languages, but I never got anything other than QLocale::Script::AnyScript.

    Is this a bug, or am I doing something wrong? Haven't found a matching QTBUG so far.

    Also, the documentation for QLocale::bcp47Name() states that it "returns the dash-separated language, script and country (and possibly other BCP47 fields) of this locale as a string": http://qt-project.org/doc/qt-5.0/qtcore/qlocale.html#bcp47Name
    However, for both Serbain (Cyrillic, Serbia) and Serbian (Latin, Serbia) I get "sr-RS" (with Qt 4.8.5) or just "sr" (with Qt 5.4.2, due to an already reported regression https://bugreports.qt.io/browse/QTBUG-34872). I never get the script in the result string.

    As a result, I couldn't find a regular way to distinguish between these locales. A possible workaround may be to examine the QLocale::system().nativeLanguageName(), but that's a very ugly hack that doesn't provide the solution for the general case, and I would rather avoid it if possible.

    Thanks in advance for any help with this.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 8 Jun 2015, 07:18 last edited by
      #2

      Hi and welcome to devnet,

      Seems like there's indeed something going on. What results should you have exactly ?

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

      D 1 Reply Last reply 8 Jun 2015, 08:04
      0
      • S SGaist
        8 Jun 2015, 07:18

        Hi and welcome to devnet,

        Seems like there's indeed something going on. What results should you have exactly ?

        D Offline
        D Offline
        djtrifun
        wrote on 8 Jun 2015, 08:04 last edited by djtrifun 6 Aug 2015, 14:01
        #3

        Hello SGaist,

        Thanks for your response. I expect for Serbian (Cyrillic, Serbia) to get:

        • 2 (QLocale::Script::CyrillicScript) from QLocale::system().script(), and
        • "sr-Cyrl-RS" from QLocale::system().bcp47Name().

        Similarly, for Serbian (Latin, Serbia) I expect:

        • 7 (QLocale::Script::LatinScript) from QLocale::system().script(), and
        • "sr-Latn-RS" from QLocale::system().bcp47Name().

        Should I open new bugs for script() and bcp47Name()?

        This is the workaround I made for bcp47Name:

        QString bcp47Name;
        
        #ifdef Q_OS_WIN
        wchar_t buffer[LOCALE_NAME_MAX_LENGTH];
        ::GetUserDefaultLocaleName(buffer, LOCALE_NAME_MAX_LENGTH);
        bcp47Name = QString::fromWCharArray(buffer);
        #else
        bcp47Name = QLocale::system().bcp47Name();
        #endif
        

        But didn't have a chance to try it on non-Windows platforms yet.

        Thanks!

        1 Reply Last reply
        0

        2/3

        8 Jun 2015, 07:18

        • Login

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