gpt4 book ai didi

qt - 我可以加载多个 QTranslator 文件,每个文件用于我的应用程序的不同部分吗?

转载 作者:行者123 更新时间:2023-12-03 00:05:03 26 4
gpt4 key购买 nike

我可以将翻译器安装为 myApp.installTranslator(&translator)

是否可以拥有多个翻译文件并从应用程序的不同部分加载它们?我该怎么做?

最佳答案

是的,可以。正如医生所说:

Adds the translation file translationFile to the list of translation files to be used for translations.

Multiple translation files can be installed. Translations are searched for in the reverse order in which they were installed, so the most recently installed translation file is searched first and the first translation file installed is searched last. The search stops as soon as a translation containing a matching string is found.

Installing or removing a QTranslator, or changing an installed QTranslator generates a LanguageChange event for the QCoreApplication instance. A QApplication instance will propagate the event to all toplevel windows, where a reimplementation of changeEvent can re-translate the user interface by passing user-visible strings via the tr() function to the respective property setters. User-interface classes generated by Qt Designer provide a retranslateUi() function that can be called.

The function returns true on success and false on failure.

您需要加载一些翻译文件,qApp 宏来获取 main() 函数外部的 QApplication 实例,并执行以下操作:

QTranslator translator;//somewhere

void MainWindow::on_someButton_clicked()
{
translator.load("://en.qm");
qApp->installTranslator( &translator );
ui->retranslateUi(this); //for Qt designer
}

您还可以通过以下方式删除翻译器:

void MainWindow::on_someButton_2_clicked()
{
qApp->removeTranslator(&translator);
ui->retranslateUi(this);
}

国际化是一个重要部分,因此我还可以建议下一个链接:

Internationalization with Qt

Writing Source Code for Translation

还有书籍:

Foundations of Qt Development (Expert's Voice in Open Source) 第10章

C++ GUI Programming with Qt 4 (2nd Edition) (Prentice Hall Open Source Software Development Series) 第18章

Qt4.8. Professionalnoe programmirovanie na C++ (Russian) 第 31 章(针对俄语使用者)

关于qt - 我可以加载多个 QTranslator 文件,每个文件用于我的应用程序的不同部分吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27619595/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com