From 235292710b3eaf9bdd7e7fb4919f77e54143c492 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Fri, 19 Jun 2015 13:11:17 +0200 Subject: Doc: Improve code snippet in QTranslator overview Use translator::load(QLocale(), ...) which loads the a translation mapping the users preferred languages, instead of just hardcoding one. This is arguably the more common (and interesting) case. Also, QPushButton::tr() does place the string in the "QPushButton" namespace, which is just wrong (TM). Change-Id: Id22851556b3f876da3b756b452811e07fc7b173e Reviewed-by: Oswald Buddenhagen --- src/corelib/doc/snippets/hellotrmain.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/corelib/doc') diff --git a/src/corelib/doc/snippets/hellotrmain.cpp b/src/corelib/doc/snippets/hellotrmain.cpp index 201202b7b3..dcf5805a8a 100644 --- a/src/corelib/doc/snippets/hellotrmain.cpp +++ b/src/corelib/doc/snippets/hellotrmain.cpp @@ -44,10 +44,11 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); QTranslator translator; - translator.load("hellotr_la"); - app.installTranslator(&translator); + // look up e.g. :/translations/myapp_de.qm + if (translator.load(QLocale(), QLatin1String("myapp"), QLatin1String("_"), QLatin1String(":/translations"))) + app.installTranslator(&translator); - QPushButton hello(QPushButton::tr("Hello world!")); + QPushButton hello(QCoreApplication::translate("main", "Hello world!")); hello.resize(100, 30); hello.show(); -- cgit v1.2.3