Some strings can't be translated in the qt project.
-
In my qt project, there are some strings can't be translated, such as the following code:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);QTranslator trans; trans.load("gui_zh"); QApplication::installTranslator(&trans); ui->retranslateUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::on_pushButton_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("open"), QDir::currentPath(), "*.cpp");
}the "open" string , be used in getOpenFileName() function, can't be translated to Chinese string "打开", but other strings, like the pushButton text, can be translated to Chinese string. There is the "Q_OBJECT" in my class, and I have generate *.qm file. I don't know why some stings can be translated, but other strings can't. May I ask for a favor, Thanks!
-
Hi and welcome to devnet,
Are you doing dynamic translation with your application ? Or only when starting it ?
-
[quote author="SGaist" date="1388094087"]Hi and welcome to devnet,
Are you doing dynamic translation with your application ? Or only when starting it ?[/quote]
Only when starting it, not dynamic translation .
-
[quote author="SGaist" date="1388094087"]Hi and welcome to devnet,
Are you doing dynamic translation with your application ? Or only when starting it ?[/quote]
Are there some differences between dynamic translation and only when starting it?
-
You should move the translator related code in your main function. The translator must be installed before creating any widgets. Have a look at the QTranslator documentation for more information