Results 1 to 6 of 6

Thread: Usage of QT_TR_NOOP()

  1. #1
    Join Date
    Nov 2007
    Posts
    31
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post Usage of QT_TR_NOOP()

    Hi everybody,

    I would like to know usage of QT_TR_NOOP() (not QT_TRANSLATE_NOOP()).

    I use the Qt SDK 4.5.1 in Linux/X11 and work in Qt Creator 1.1.0.

    I wrote a sample code as follows.
    Qt Code:
    1. #include <QApplication>
    2. #include <QMainWindow>
    3. #include <QTranslator>
    4. #include <QString>
    5. #include <QtGlobal>
    6.  
    7. class MyMessage {
    8. Q_DECLARE_TR_FUNCTIONS(MyMessage)
    9. public:
    10. MyMessage(){}
    11. ~MyMessage(){}
    12.  
    13. static QString GetMessage() {
    14. static const char* message = QT_TR_NOOP("Hello");
    15. return QString(QObject::tr(message));
    16. }
    17. };
    18.  
    19. int main(int argc, char *argv[])
    20. {
    21. QApplication application(argc, argv);
    22. QMainWindow mainWindow;
    23. QTranslator translator;
    24.  
    25. translator.load("./MyAppMessages.qm");
    26. application.installTranslator(&translator);
    27.  
    28. mainWindow.setWindowTitle(MyMessage::GetMessage());
    29. mainWindow.show();
    30.  
    31. return application.exec();
    32. }
    To copy to clipboard, switch view to plain text mode 

    And I made "MyAppMessages.qm" with lupdate, Qt Linguist, and lrelease to translate the message "Hello" into Japanese.
    And I built and ran the program.
    but window title was "Hello" yet.

    Although I am studying English hard, my English is not great yet,
    and I may make many mistakes. So, please be patient with me.

    Thank you very much for any kind of help.
    kichi

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

    Default Re: Usage of QT_TR_NOOP()

    QT_TR_NOOP only marks the text as something that may need translation (so that it shows up in Linguist) but it doesn't do any translating. For that you need to use tr().
    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. The following user says thank you to wysota for this useful post:

    kichi (4th May 2009)

  4. #3
    Join Date
    Nov 2007
    Posts
    31
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Usage of QT_TR_NOOP()

    Thank you very much.
    kichi

  5. #4
    Join Date
    Nov 2007
    Posts
    31
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post Re: Usage of QT_TR_NOOP()

    In my understanding, not only QT_TR_NOOP, but also QT_TRANSLATE_NOOP
    merely marks the text for extraction.
    so, I guess that "Hello" is displayed, in the following code.
    but, "Hello" was translated into Japanese.
    Why?

    Qt Code:
    1. #include <QApplication>
    2. #include <QMainWindow>
    3. #include <QTranslator>
    4. #include <QtGlobal>
    5.  
    6. static const char* greetingList[] = {
    7. QT_TRANSLATE_NOOP("Greeting", "Good morning"),
    8. QT_TRANSLATE_NOOP("Greeting", "Goodbye")
    9. };
    10.  
    11. int main(int argc, char *argv[])
    12. {
    13. QApplication application(argc, argv);
    14. QMainWindow mainWindow;
    15. QTranslator translator;
    16.  
    17. translator.load("./MyAppMessages.qm");
    18. application.installTranslator(&translator);
    19.  
    20. mainWindow.setWindowTitle(application.translate("Greeting", greetingList[0]));
    21. mainWindow.show();
    22.  
    23. return application.exec();
    24. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Usage of QT_TR_NOOP()

    Because you called QCoreApplication::translate().
    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. #6
    Join Date
    Nov 2007
    Posts
    31
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Usage of QT_TR_NOOP()

    I made a mistake.
    I'm sorry.
    I understand.
    Thank you very much.
    kichi

Similar Threads

  1. Bad memory usage on QWebView I think
    By jiturra in forum Qt Programming
    Replies: 15
    Last Post: 21st January 2014, 20:35
  2. Why is my application's CPU usage always > 50%
    By richardander in forum Qt Programming
    Replies: 10
    Last Post: 14th October 2010, 22:22
  3. Very high CPU usage with QTableView and MVC
    By montylee in forum Qt Programming
    Replies: 7
    Last Post: 24th March 2009, 06:14
  4. Excess CPU usage during Paint
    By vairamuthu.g in forum Qt Programming
    Replies: 1
    Last Post: 17th March 2009, 09:59
  5. rotate operation and cpu usage
    By ersin.ozkan in forum Qt Programming
    Replies: 2
    Last Post: 30th December 2008, 06:42

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
  •  
Qt is a trademark of The Qt Company.