Important: Please read the Qt Code of Conduct -

Loading qm file from ressources fails

  • I try to load a qm file from the ressource system but it fails.

    The code:

    LanguageSelector::LanguageSelector(QObject *parent)
        : QObject{parent}, mTranslator{new QTranslator{this}}
    void LanguageSelector::loadEnglish()
        QFile file(":/translations/quiz.en.qm");
        if (!, QIODevice::ReadOnly)) {
            qDebug() << "Can't find it!";
        if (!mTranslator->load(QLocale(QLocale::English), QLatin1String("quiz.en"),
                               QLatin1String(":/translations"))) {
            qDebug() << "load english failed";

    Strangely I don't get an error on the QFile check as expected but loading the file with QTranslator fails. What could be the Issue?

    The file with the code is in the folder:


    The ressource file for the languages is directlyy in root:


    The translations file:

        <qresource prefix="/">

  • @sandro4912 said in Loading qm file from ressources fails:

    mTranslator->load(QLocale(QLocale::English), QLatin1String("quiz.en"), QLatin1String(":/translations"))) {

    you may want to check the documentation of QTranslator::load() method

  • @Pablo-J-Rogina

    I checked it but I could not find an issue

  • I missed stating the separator in the method. Like this it works:

    void LanguageSelector::loadLanguage(const QLocale::Language &newLanguage)
        if (!mTranslator->load(QLocale(newLanguage), QLatin1String("quiz"),
                               QLatin1String(":/translations"))) {
            auto metaEnum = QMetaEnum::fromType<QLocale::Language>();
            qDebug() << tr("load language %1 failed")
        else {
            qDebug() << mTranslator->filePath();

Log in to reply