QGuiApplication::installTranslator has no effect
-
I am trying to translate my application to german.
Following the documentation, I have added qsTr() around the text that I am using, e.g.:
Label { id: welcomeText Layout.alignment: Qt.AlignHCenter Layout.topMargin: 24 text: qsTr("Welcome back!") color: Style.colorText font.bold: true font.pointSize: Fonts.size26 }
Then I have added the following to my CMakeLists.txt
qt_add_translations(presentation TS_FILES librum_de.ts) add_dependencies(presentation presentation_lupdate) add_dependencies(presentation presentation_lrelease) add_dependencies(presentation update_translations)
Which correctly generates the
librum_de.ts
file. I have edited it using the Linguist tool and added the missing translations and then recompiled my application which lead to the .qm file to be properly generated.Now in my main.cpp when trying to load it:
QTranslator translator; qDebug() << translator.load(":/i18n/librum_de"); qDebug() << QGuiApplication::installTranslator(&translator);
Both the qDebug() statements give me true, thus it seems to load it just fine, but none of the text inside my application actually changes.
Does someone have an idea
-
@Creaperdown said in QGuiApplication::installTranslator has no effect:
QTranslator translator;
Where exactly is this line located? Maybe translator goes out of scope and is deleted?
-
@jsulm Thank you, I didn't have that in mind at all. I extracted it into a function that I was calling from main, but I have just seen that the documentation says that it doesnt take ownership of it, so it indeed goes out of scope.
Moving it back into the main function fixes it!
-