Results 1 to 2 of 2

Thread: Why the *.qm file only translates application partly?

  1. #1
    Join Date
    Sep 2009
    Location
    Nanjing, China
    Posts
    46
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Why the *.qm file only translates application partly?

    Hi, there! I have a strange problem about .qm file which generated by linguist. For example, I have a main window which extends QMainWindow and 2 dialogs which extends QDialog. Then I use lupdate and linguist to generate .qm file to translate my application. But when I run this application, only the main window is translated, the dailogs are not! I don't know why. Here is my code, I think there maybe are some problem with the namespace.

    Qt Code:
    1. // mainwindow.cpp
    2. #include <QAction>
    3. #include <QToolBar>
    4. #include "mainwindow.h"
    5. #include "dialog1.h"
    6. #include "dialog2.h"
    7.  
    8. app::MainWindow::MainWindow(QWidget *parent)
    9. : QMainWindow(parent)
    10. {
    11. QAction *openDialog1 = new QAction(tr("open dialog 1"), this);
    12. QAction *openDialog2 = new QAction(tr("open dialog 2"), this);
    13.  
    14. connect(openDialog1, SIGNAL(triggered()), this, SLOT(showDialog1()));
    15. connect(openDialog2, SIGNAL(triggered()), this, SLOT(showDialog2()));
    16.  
    17. QToolBar *bar = addToolBar(tr("Tool Bar"));
    18. bar->addAction(openDialog1);
    19. bar->addAction(openDialog2);
    20. }
    21.  
    22. app::MainWindow::~MainWindow()
    23. {
    24.  
    25. }
    26.  
    27. void app::MainWindow::showDialog1()
    28. {
    29. Dialog1 *d = new Dialog1(this);
    30. d->exec();
    31. }
    32.  
    33. void app::MainWindow::showDialog2()
    34. {
    35. Dialog2 *d = new Dialog2(this);
    36. d->exec();
    37. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // dialog1.cpp
    2. #include "dialog1.h"
    3.  
    4. app::Dialog1::Dialog1(QWidget *parent)
    5. : QDialog(parent)
    6. {
    7. setWindowTitle(tr("Dialog 1"));
    8. }
    9.  
    10. // Class Dialog2 is the same as Dialog1, so the file is ingored.
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // main.cpp
    2. #include <QtGui/QApplication>
    3. #include <QDebug>
    4. #include <QTranslator>
    5. #include "mainwindow.h"
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. using namespace app;
    10.  
    11. QApplication a(argc, argv);
    12.  
    13. qDebug() << t.load("../res/i18n_zh_CN");
    14. a.installTranslator(&t);
    15.  
    16. MainWindow w;
    17. w.show();
    18. return a.exec();
    19. }
    To copy to clipboard, switch view to plain text mode 

    qDebug() outputs true. This has confused for several days....

  2. #2
    Join Date
    Sep 2009
    Location
    Nanjing, China
    Posts
    46
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why the *.qm file only translates application partly?

    OK, I found the reason! Because tr() must with Q_OBJECT! I added this macro and it works!

Similar Threads

  1. How to set the application name using pro file
    By live_07 in forum Qt Programming
    Replies: 1
    Last Post: 9th November 2007, 21:20
  2. How to read/write PDF file from Qt Application?
    By rajesh in forum Qt Programming
    Replies: 5
    Last Post: 30th August 2007, 08:39
  3. Opening pdf file in Qt application
    By jyoti kumar in forum Qt Programming
    Replies: 2
    Last Post: 20th June 2007, 18:35
  4. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  5. Application build Mac PPC/Intel pro file?
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 28th June 2006, 13:27

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.