I'm building a small QtQuick demo for a client that needs language translation. I want to instantiate a QTranslator, load the translation files and then use them in qsTr() macros in the app.
It seems to be fine running the app as a Linux desktop app, or on a Mac desktop, or even on an iPhone.
But building and running the app on Android (and, weirdly on the iPhone simulator) the translations are not happening: the default strings are being displayed.
I've tried putting breakpoints and debug logging around the code in the main() function in main.cpp, and it seems that main() is not being called at all in the Android version.
Here is the code in my main.cpp:

Qt Code:
  1. #include <QGuiApplication>
  2. #include <QQmlApplicationEngine>
  3. #include <QTranslator>
  4. #include <QtDebug>
  5. #include <iostream>
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9. QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
  10. QGuiApplication app(argc, argv);
  11. QLocale::setDefault(QLocale::system());
  12. QTranslator translator;
  13. QLocale locale;
  14. std::cout << "Hello World" << locale.name().toStdString() << std::endl;
  15. if (translator.load(locale,QLatin1String("mockup"),QLatin1String("_"),QLatin1String(":/translations"))) {
  16. app.installTranslator(&translator);
  17. qDebug() << "Installed translator for " << locale.name();
  18. }
  19. else
  20. {
  21. qDebug() << "Cannot load translator " << locale.name();
  22.  
  23. }
  24. QQmlApplicationEngine engine;
  25. const QUrl url(QStringLiteral("qrc:/main.qml"));
  26. QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
  27. &app, [url](QObject *obj, const QUrl &objUrl) {
  28. if (!obj && url == objUrl)
  29. QCoreApplication::exit(-1);
  30. }, Qt::QueuedConnection);
  31. engine.load(url);
  32. return app.exec();
  33. }
To copy to clipboard, switch view to plain text mode 

I don't see any of the log statements in console output when I run on the Android platform in QtCreator, whereas other platforms do show these log messages.