Results 1 to 3 of 3

Thread: Override locale with QSystemLocale

  1. #1
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Question Override locale with QSystemLocale

    Hi,

    I need QString::localeAwareCompare to properly sort German names.
    This works on my desktop.

    Unfortunately my tablet seems to provide a wrong system locale.

    I've tried
    Qt Code:
    1. mainWin.setLocale(QLocale(QLocale::German,QLocale::Germany));
    To copy to clipboard, switch view to plain text mode 
    as well as
    Qt Code:
    1. QLocale::setDefault(QLocale(QLocale::German,QLocale::Germany));
    To copy to clipboard, switch view to plain text mode 
    but "Z" is still less than "Ö" (When "Ö" shoud be between "O" and "P").

    I've looked into QSystemLocale, but there are no setter methods (and the documentation
    is vague, actually saying " only useful in very rare cases."), so I don't understand how I
    can use this. I didn't find anything particularly helpful about this on web research or in this Forum.

    Is there any way to override the system locale and force Qt into using
    a specific locale?

    How do I use QSystemLocale (if at all) to force Qt into German sorting?

  2. #2
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Override locale with QSystemLocale

    Nobody with an idea or a pointer to some documentation?

  3. #3
    Join Date
    Nov 2012
    Posts
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Override locale with QSystemLocale

    This code work for me.
    Qt Code:
    1. #include <QSystemLocale>
    2.  
    3. class MySystemLocale : QSystemLocale
    4. {
    5.  
    6. public: MySystemLocale() { }
    7.  
    8. QVariant query(QueryType type, QVariant in) const
    9. {
    10. if (type==QSystemLocale::DecimalPoint) {
    11. return ".";
    12. }
    13. return QSystemLocale::query(type, in);
    14. }
    15.  
    16. };
    17.  
    18. int main(int argc, char *argv[])
    19. {
    20. MySystemLocale appSystemLocale; // work fine
    21. QApplication a(argc, argv);
    22. // MySystemLocale appSystemLocale;// not work
    23.  
    24. return a.exec();
    25. }
    To copy to clipboard, switch view to plain text mode 

  4. The following user says thank you to frost_asm for this useful post:

    sedi (22nd August 2013)

Similar Threads

  1. Locale and database
    By lynnH in forum Qt Programming
    Replies: 5
    Last Post: 24th February 2012, 17:40
  2. How to change locale
    By memus in forum Newbie
    Replies: 5
    Last Post: 29th May 2011, 13:50
  3. About locale issue
    By xiajingan in forum Qt Programming
    Replies: 3
    Last Post: 26th February 2009, 22:18
  4. Setting locale for the whole app
    By maverick_pol in forum Qt Programming
    Replies: 2
    Last Post: 22nd June 2008, 23:53
  5. Qt4 and system locale
    By L.Marvell in forum Qt Programming
    Replies: 9
    Last Post: 15th January 2007, 14:00

Tags for this Thread

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.