I use QQuickView to show qml interface in widget application
m_window = new QQuickView();
m_container = QWidget::createWindowContainer(m_window,hostWidget,Qt::FramelessWindowHint);
m_container->setFocusPolicy(Qt::TabFocus);
m_window->setResizeMode(QQuickView::SizeRootObjectToView);
m_window->setSource(file_url);
I need to make qml interface multilingual, so before instantiating QQuickView i install new translator to application:
m_qmlTranslator = new QTranslator(this); // this - host QWidget
m_qmlTranslator->load(QString::fromUtf8("translate_%1").arg(QLocale::system().name()),strTranslationDir);
QScopedPointer<QCoreApplication> pAppl(QApplication::instance());
pAppl->installTranslator(m_qmlTranslator);
both load and installTranslator functions returns true. (Translations for target language exists in ts-file and compiled to qm-file which placed to right dir)
Problem is that in C++ translations work well, following code ouputs string in target language
qDebug() << tr("translation test");
but in qml interface diplayed by QQuickView string stays untraslated
Text {
id: title
text: qsTr("translation test")
font.pixelSize: 36
font.bold: true
anchors.horizontalCenter: parent.horizontalCenter
}
while debugging i found out that QCoreApplication::translate
function is called by Qt for qsTr("translation test")
with correct sourceText variable, but all QTranslators from self->d_func()->translators
returns null QStrings so visible text stays untranslated.
Any thoughts why this happens and how to make text to be translated in QQuickView?