<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Dynamic multilangual re-evaluation of qml Text in C++ using qsTr() function in qml]]></title><description><![CDATA[<p dir="auto">Hi everyone,</p>
<p dir="auto">I would like to know if there is any possibility to use qsTr() or it's functionality in C++ to re-evaluate a qml Text element via C++ instead of the approach suggested in this article when changing the language of the application. <a href="http://qt-project.org/wiki/How_to_do_dynamic_translation_in_QML" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/wiki/How_to_do_dynamic_translation_in_QML</a></p>
<p dir="auto">The qml text element which gets translated with the according .qm file to different languages.<br />
@<br />
Text {<br />
text: qsTr("Hello World")<br />
onTextChanged: console.debug(text)<br />
}<br />
@</p>
<p dir="auto">Somewhere after loading the new language file, I get the according text element and try to translate the new text manually via c++ but in general the textTranslated is never translated correctly! It is always the origin text - because no translation was found.</p>
<p dir="auto">@<br />
// ... loading the new translation file</p>
<pre><code>if(m_translator-&gt;load(languageFile, filePath)) {
    qApp-&gt;installTranslator(m_translator);
}

// ...

QObject *child = children.at(i); // the text element object
QString textContent = child-&gt;property("text").toString();
QString textTranslated = child-&gt;tr(qPrintable(textContent)); // returns textContent
//QString textTranslated = child-&gt;parent()-&gt;tr(qPrintable(textContent)); // returns textContent
//QString textTranslated = m_translator-&gt;translate(child-&gt;metaObject()-&gt;className(),qPrintable(textContent));  // returns ""
//QString textTranslated = QApplication::translate(child-&gt;metaObject()-&gt;className(),textContent.toStdString().c_str()); // returns textContent
qDebug() &lt;&lt; "[Translator] text" &lt;&lt; qPrintable(textContent) &lt;&lt; " of element " &lt;&lt; child &lt;&lt; textTranslated;
child-&gt;setProperty("text",textTranslated);
</code></pre>
<p dir="auto">@</p>
<p dir="auto">The translate functions need a context - which is char* - as first parameter, but I don't really know which content this might be, because I assume the qml object content would be something different.</p>
<p dir="auto">I didn't found any implementation of qsTr() neither in the source code nor in the web. It this a real function or only a makro for the Linguist. How does the translation process work anyway?</p>
<p dir="auto">Cheers,<br />
David</p>
]]></description><link>https://forum.qt.io/topic/27533/dynamic-multilangual-re-evaluation-of-qml-text-in-c-using-qstr-function-in-qml</link><generator>RSS for Node</generator><lastBuildDate>Mon, 16 Mar 2026 11:41:57 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/27533.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 23 May 2013 13:25:54 GMT</pubDate><ttl>60</ttl></channel></rss>