Results 1 to 2 of 2

Thread: Help with QTranslator

  1. #1
    Join Date
    Jun 2008
    Posts
    83
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Help with QTranslator

    Hi:

    I'm trying my hand at a little internationalization and I wanted to start with a simple app and two languages: english and spanish. I managed to succesfully load the spanish packet and saw everything in my application as it should. Next I wanted to implement a bit of code so that the user could choose the language at the program startup since changing it on the fly is apparently pretty complicated. Since I only had two options I tried this in main.cpp.

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. LanguageDialog diag; \\
    5. diag.exec(); \\
    6. if (diag.shouldTranslate()){\\
    7. QTranslator translator;
    8. translator.load(QString("mastermind_es"));
    9. a.installTranslator(&translator);
    10. }\\
    11. Mastermind w;
    12. w.show();
    13. return a.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

    And it doesn't work. Nothing gets translated no matter what I choose and I've allready checked, I effectively enter the if sentence in spanish is chosen in the diag object.
    If the lines with a \\ are commented then I get my app translated (everytime) obviously.

    Can anyone tell me what I'm doing wrong?

    Thanks for any help in advance.

  2. #2
    Join Date
    Jun 2008
    Posts
    83
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Help with QTranslator

    So I've kind of answered my own question.

    The problem is that in the code I wrote the translator object only exists in the scope of the if sentence so that when it exists it dissapears.

    The problem was solved by simply declaring it like this:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. LanguageDialog diag; \\
    5. diag.exec(); \\
    6. QTranslator translator;
    7. if (diag.shouldTranslate()){\\
    8. translator.load(QString("mastermind_es"));
    9. a.installTranslator(&translator);
    10. }\\
    11. Mastermind w;
    12. w.show();
    13. return a.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Want to use QTranslator
    By santhoshv84 in forum Qt Programming
    Replies: 1
    Last Post: 27th August 2008, 15:13
  2. QDesigner + Qtranslator + QComboBox
    By Atikae in forum Qt Programming
    Replies: 3
    Last Post: 11th July 2008, 15:41
  3. Replies: 27
    Last Post: 16th May 2008, 07:33
  4. Switch QTranslator at runtime?
    By whitefurrows in forum Qt Programming
    Replies: 22
    Last Post: 6th November 2006, 11:32

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.