Results 1 to 10 of 10

Thread: Qt4 and system locale

  1. #1
    Join Date
    Jan 2006
    Location
    Ukraine, L'viv
    Posts
    57
    Thanks
    3
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Qt4 and system locale

    I need to know system locale (en, uk, ru etc.) to load appropriate translation. In Qt3 there was QTextCodec::locale() method for this but Qt4 assistant says:
    The following class members are part of the Qt 3 support layer. They are provided to help you port old code to Qt 4. We advise against using them in new code.
    Also there is QLocale class that has country(), language() and name() methods in Qt4. But there is no locale().
    On my Linux machine countryToString() gives me Default and language() - C, but locale is koi8-u. So how can I get system locale?

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine, L'viv
    Posts
    57
    Thanks
    3
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4 and system locale

    Sorry, already did it under win. Will try under Linux at home.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4 and system locale

    Quote Originally Posted by L.Marvell
    Also there is QLocale class that has country(), language() and name() methods in Qt4. But there is no locale().
    QLocale::name() looks promising:
    QString QLocale::name () const
    Returns the language and country of this locale as a string of the form "language_country", where language is a lowercase, two-letter ISO 639 language code, and country is an uppercase, two-letter ISO 3166 country code.
    See also language() and country().
    Quote Originally Posted by L.Marvell
    but locale is koi8-u.
    IMO that's the encoding, not locale.

  4. #4
    Join Date
    Jan 2006
    Location
    Ukraine, L'viv
    Posts
    57
    Thanks
    3
    Thanked 4 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4 and system locale

    Yes, exactly QLocale::name() helped. I had to look through examples before post question.

  5. #5
    Join Date
    Feb 2006
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt4 and system locale

    Hi, all!

    I have similar problem in qt4 under win.
    I want to get system encoding.

    So I do:

    Qt Code:
    1. QTextCodec * localCodec = QTextCodec::codecForLocale();
    2. QByteArray name = localCodec->name();
    To copy to clipboard, switch view to plain text mode 

    variable name contain value "System". But I want to get value "cp1251" or "koi8-r" or something else depending of value current local encoding... Value "System" is not informatively.

    Anybody know how to get name of current system encoding?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4 and system locale

    Quote Originally Posted by Sergey View Post
    Anybody know how to get name of current system encoding?
    Have you tried QTextCodec::aliases()?

  7. #7
    Join Date
    Feb 2006
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt4 and system locale

    Yes.
    it returns NULL.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4 and system locale

    Then maybe if you use QTextCodec::mibEnum() first and then get a new codec using QTextCodec::codecForMib() it will have a proper name?

  9. #9
    Join Date
    Feb 2006
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qt4 and system locale

    I wrote next code:

    Qt Code:
    1. QTextCodec * localCodec = QTextCodec::codecForLocale();
    2. int mib = localCodec->mibEnum();
    3. QTextCodec * codec = QTextCodec::codecForMib(mib);
    4. QByteArray n = codec->name();
    To copy to clipboard, switch view to plain text mode 

    variable n contain value "System"...

    Maybe this is a bug in QTextCodec?

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4 and system locale

    Quote Originally Posted by Sergey View Post
    Maybe this is a bug in QTextCodec?
    I think that rather OS doesn't specify what encoding it uses currently.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.