Improve QTranslator documentation code snippet

Use :/i18n/, because this is the place where translations are stored
by default if using qmake's CONFIG += lrelease embed_translations.

Also revert change of app.exec() done in 16da0b2cf8. First of all,
both QGuiApplication and QApplication feature overloads of exec(),
so using QCoreApplication::exec() might miss functionality.
Anyhow, while it's true that all of them are static member functions,
the vast majority of our examples and templates call them with
class member access syntax, so let's try to be consistent.

Finally, the example since a while uses QCoreApplication::translate,
not tr(), so let's not mention it in the description.

Change-Id: Ic6e5d91cf04d3f0d1a4296c5c09e790773e6fc62
Reviewed-by: Miłosz Kosobucki <milosz@kosobucki.pl>
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
bb10
Kai Koehne 2020-04-14 09:59:14 +02:00
parent 8f7e21bc50
commit ec2ac17c10
2 changed files with 6 additions and 5 deletions

View File

@ -54,15 +54,15 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
QTranslator translator;
// look up e.g. :/translations/myapp_de.qm
if (translator.load(QLocale(), QLatin1String("myapp"), QLatin1String("_"), QLatin1String(":/translations")))
// look up e.g. :/i18n/myapp_de.qm
if (translator.load(QLocale(), QLatin1String("myapp"), QLatin1String("_"), QLatin1String(":/i18n")))
QCoreApplication::installTranslator(&translator);
QPushButton hello(QCoreApplication::translate("main", "Hello world!"));
hello.resize(100, 30);
hello.show();
return QCoreApplication::exec();
return app.exec();
}
//! [0]

View File

@ -341,8 +341,9 @@ public:
Translation files are created using \l{Qt Linguist}.
The most common use of QTranslator is to: load a translation
file, install it using QCoreApplication::installTranslator(), and use
it via QObject::tr(). Here's an example \c main() function using the
file, and install it using QCoreApplication::installTranslator().
Here's an example \c main() function using the
QTranslator:
\snippet hellotrmain.cpp 0