Results 1 to 6 of 6

Thread: How to change locale

  1. #1
    Join Date
    Aug 2008
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to change locale

    Hi there,
    i have problem with QLocale.
    When i try to set other locale:
    Qt Code:
    1. QLocale::setDefault(QLocale::English, QLocale::UnitedStates);
    2. qDebug() << QLocale::system().language();
    To copy to clipboard, switch view to plain text mode 
    Output should be 31 but is 90 (my locale). Why?

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to change locale

    You do not set the system locale when using the setDefault function, only the locale for your program (process)

  3. #3
    Join Date
    Aug 2008
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to change locale

    Quote Originally Posted by tbscope View Post
    You do not set the system locale when using the setDefault function, only the locale for your program (process)
    I need to get QDate::fromString from english str locale. How can i do that?

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to change locale

    Since setDefault works on the current process, that should function correctly. The only thing you can't do is change the locale of other applications.

  5. #5
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How to change locale

    Try the following:

    Qt Code:
    1. QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates));
    2.  
    3. myDate.fromString(..., Qt::DefaultLocaleShortDate);
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Apr 2011
    Posts
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to change locale

    how can you change the locale from a qml application?

Similar Threads

  1. Locale-aware QString::contains()
    By victor.fernandez in forum Qt Programming
    Replies: 1
    Last Post: 25th November 2009, 18:58
  2. About locale issue
    By xiajingan in forum Qt Programming
    Replies: 3
    Last Post: 26th February 2009, 22:18
  3. Setting locale for the whole app
    By maverick_pol in forum Qt Programming
    Replies: 2
    Last Post: 22nd June 2008, 23:53
  4. QDateTime GMT add sec. or - sec. from locale time....
    By patrik08 in forum Qt Programming
    Replies: 2
    Last Post: 20th February 2007, 17:39
  5. Qt4 and system locale
    By L.Marvell in forum Qt Programming
    Replies: 9
    Last Post: 15th January 2007, 14:00

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.