Results 1 to 20 of 38

Thread: QSettings with translation

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    692
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSettings with translation

    Hi to all,
    I would know how set the settings of my application to manage translation.
    For example if I choose english, when I restart the application I would have english as language.

    Best Regards
    Franco Amato

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSettings with translation

    What have you already done to try and solve your problem?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    692
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings with translation

    Quote Originally Posted by wysota View Post
    What have you already done to try and solve your problem?
    pass a file path, set a QString, but I would know if there is a specific setting
    Franco Amato

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSettings with translation

    So does it work or not? If not, what doesn't work?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    692
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings with translation

    Quote Originally Posted by wysota View Post
    So does it work or not? If not, what doesn't work?
    Doesn't work! If I change language it always load the same.
    So I ask again: is there a specific setting for language translation?
    Franco Amato

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSettings with translation

    So how exactly do you store the setting?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    692
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings with translation

    Quote Originally Posted by wysota View Post
    So how exactly do you store the setting?
    Qt Code:
    1. void MainWindow::closeEvent(QCloseEvent *ce )
    2. {
    3. Q_UNUSED(ce);
    4. writeSettings();
    5. }
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. void MainWindow::writeSettings()
    2. {
    3. QSettings settings("config.ini", QSettings::IniFormat);
    4. /* language group */
    5. settings.beginGroup("language");
    6. settings.setValue("lang", m_language);
    7. settings.endGroup();
    8. /* paths group */
    9. settings.beginGroup("paths");
    10. settings.setValue("w1_source", m_w1SourceDir);
    11. settings.setValue("w2_source", m_w2SourceDir);
    12. settings.setValue("w1_output", m_w1OutputDir);
    13. settings.setValue("w2_output", m_w2OutputDir);
    14. settings.endGroup();
    15. /* colors group */
    16. settings.beginGroup("colors");
    17. settings.setValue("background", m_bgColor);
    18. settings.setValue("waveform", m_wfColor);
    19. settings.setValue("timeline", m_tlColor);
    20. settings.setValue("markers" , m_mkColor);
    21. settings.setValue("selection", m_slColor);
    22. settings.endGroup();
    23. /* background */
    24. settings.beginGroup("background");
    25. settings.setValue("file", m_bgFile);
    26. settings.setValue("loop_interval", m_loopInterval);
    27. settings.setValue("loop_mode", m_loopMode);
    28. settings.endGroup();
    29. /* steps */
    30. settings.beginGroup("steps");
    31. settings.setValue("sec", m_sstep);
    32. settings.setValue("min", m_mstep);
    33. settings.endGroup();
    34. }
    To copy to clipboard, switch view to plain text mode 
    Franco Amato

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSettings with translation

    I'm not sure that storing the settings in the current working directory is a good idea. Anyway, how does the reading part look like? Also does the configuration file get created? Does it have proper contents?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    692
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings with translation

    Quote Originally Posted by wysota View Post
    I'm not sure that storing the settings in the current working directory is a good idea.
    So how must I do?
    Anyway, how does the reading part look like?
    It works for all settings except for the language

    Also does the configuration file get created? Does it have proper contents?
    Yes the content of the ini file is correct
    Franco Amato

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSettings with translation

    Quote Originally Posted by franco.amato View Post
    So how must I do?
    Either store the settings in a "well known location" like the user's home directory or use the application binary directory or let Qt choose the proper location.

    It works for all settings except for the language
    Please provide enough information for us to see how you try to apply the language change using your settings. I'm tired of having to drag every piece of information out of you. If you want help, provide enough information to see where the problem might be. And do it always, not only in this thread, you have already over 400 posts on this forum, for God's sake! Every thread of yours is at least 5 times longer than questions asked by others. If you have problem with specifying your problem, maybe you should take a look at how others do it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    692
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings with translation

    Quote Originally Posted by wysota View Post
    Either store the settings in a "well known location" like the user's home directory or use the application binary directory or let Qt choose the proper location.
    How can I let Qt decide where? Can I speak with Qt and ask where it would store the configuration file?


    Please provide enough information for us to see how you try to apply the language change using your settings. I'm tired of having to drag every piece of information out of you. If you want help, provide enough information to see where the problem might be. And do it always, not only in this thread, you have already over 400 posts on this forum, for God's sake! Every thread of yours is at least 5 times longer than questions asked by others. If you have problem with specifying your problem, maybe you should take a look at how others do it.
    Please wysota give a look at your replies. They are also written with Morse code, and I always have to ask 'please can you be more clear' or I always have to beg for 2 lines of clarifing code of example as in the above statement ( let Qt decide where ).
    I'm sure I'm not the only person thinking that.
    I stopped to post questions in the 'Programming' sections hoping to have more clear replies (to improve my Qt level) but is not so.
    Franco Amato

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

    Default Re: QSettings with translation

    and you read your settings file how?

  13. #13
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    692
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSettings with translation

    Quote Originally Posted by squidge View Post
    and you read your settings file how?
    This is my routine to read settings:

    Qt Code:
    1. void MainWindow::readSettings()
    2. {
    3. QSettings settings("config.ini", QSettings::IniFormat);
    4. /* language group */
    5. settings.beginGroup("language");
    6. m_language = settings.value("lang", "en").toString();
    7. settings.endGroup();
    8. /* paths group */
    9. settings.beginGroup("paths");
    10. m_w1SourceDir = settings.value("w1_source", "C:").toString();
    11. m_w2SourceDir = settings.value("w2_source", "C:").toString();
    12. m_w1OutputDir = settings.value("w1_output", "C:").toString();
    13. m_w2OutputDir = settings.value("w2_output", "C:").toString();
    14. settings.endGroup();
    15. /* background file */
    16. settings.beginGroup("background");
    17. m_bgFile = settings.value("file", "./audio de fondo/Grabacion_marca de agua_cruz report - MONO.mp3").toString();
    18. m_loopMode = settings.value("loop_mode", "loop").toString();
    19. m_loopInterval = settings.value("loop_interval", 5).toInt();
    20. settings.endGroup();
    21. /* steps */
    22. settings.beginGroup("steps");
    23. m_sstep = settings.value("sec", 1).toInt();
    24. m_mstep = settings.value("min", 1).toInt();
    25. settings.endGroup();
    26. /* colors group */
    27. settings.beginGroup("colors");
    28. QColor defColor = Qt::white;
    29. QVariant colVariant = defColor;
    30. m_bgColor = settings.value( "background", colVariant ).value<QColor>();
    31. m_wfColor = settings.value( "waveform", Qt::darkBlue ).value<QColor>();
    32. m_tlColor = settings.value( "timeline", Qt::darkRed ).value<QColor>();
    33. m_mkColor = settings.value( "markers", Qt::yellow ).value<QColor>();
    34. m_slColor = settings.value( "selection", Qt::red ).value<QColor>();
    35. settings.endGroup();
    36. }
    To copy to clipboard, switch view to plain text mode 

    I installed 2 translation files in the main.cpp so:

    Qt Code:
    1. QApplication app(argc, argv);
    2.  
    3. QTranslator enTranslator;
    4. enTranslator.load( "ecpstudio_en");
    5. app.installTranslator( &enTranslator );
    6.  
    7. QTranslator esTranslator;
    8. esTranslator.load( "ecpstudio_es");
    9. app.installTranslator( &esTranslator );
    To copy to clipboard, switch view to plain text mode 

    then I perform a test on the m_language variable ( after read the configuration file )

    Qt Code:
    1. if ( QString::compare(m_language, "en", Qt::CaseInsensitive) == 0 )
    2. // here I would do effective the english translation file
    3. else
    4. // here I would do effective the spanish translation file
    To copy to clipboard, switch view to plain text mode 
    Last edited by franco.amato; 21st October 2010 at 22:53.
    Franco Amato

Similar Threads

  1. UI translation
    By Annihilator in forum Qt Programming
    Replies: 2
    Last Post: 28th September 2010, 11:37
  2. translation
    By weixj2003ld in forum Qt Programming
    Replies: 8
    Last Post: 31st May 2010, 01:01
  3. Translation of UI
    By elizabeth.h1 in forum Qt Programming
    Replies: 1
    Last Post: 2nd November 2009, 11:01
  4. Migrate Qt3 QSettings to Qt4 QSettings
    By hvengel in forum Qt Programming
    Replies: 3
    Last Post: 22nd February 2008, 03:21
  5. Translation
    By merlvingian in forum Qt Programming
    Replies: 1
    Last Post: 14th August 2007, 17:45

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.