Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGuiApplication::installTranslator fails
Forum Updated to NodeBB v4.3 + New Features

QGuiApplication::installTranslator fails

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 1.1k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    It seems you are trying to use the full path to your translation files and that is the issue. If you look at the class documentation, you'll see that the folder where to find the file is set in a different parameter.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by Paul Colby
      #3

      Hi @Creaperdown,

      @SGaist said in QGuiApplication::installTranslator fails:

      It seems you are trying to use the full path to your translation files and that is the issue.

      I don't believe that's an issue. As per the doc's you linked:

      Loads filename ... which may be an absolute file name or relative to directory.

      Assuming that m_translator.load() did indeed succeed, then, just poking around the QCoreApplication::installTranslator() source, here's a few reasons I can see it might return false:

      1. &m_translator is nullptr (seems impossible in your case)
      2. m_translator.isEmpty() is true - easy enough for you to test.
      3. the current application instance is nullptr. ie have you made sure this code only runs after the app instance is constructed? Try checking if QCoreApplication::instance() is nullptr? Mind you, in this scenario, you should see a qWarning logged.

      Which Qt version are you using?

      SGaistS C 2 Replies Last reply
      0
      • Paul ColbyP Paul Colby

        Hi @Creaperdown,

        @SGaist said in QGuiApplication::installTranslator fails:

        It seems you are trying to use the full path to your translation files and that is the issue.

        I don't believe that's an issue. As per the doc's you linked:

        Loads filename ... which may be an absolute file name or relative to directory.

        Assuming that m_translator.load() did indeed succeed, then, just poking around the QCoreApplication::installTranslator() source, here's a few reasons I can see it might return false:

        1. &m_translator is nullptr (seems impossible in your case)
        2. m_translator.isEmpty() is true - easy enough for you to test.
        3. the current application instance is nullptr. ie have you made sure this code only runs after the app instance is constructed? Try checking if QCoreApplication::instance() is nullptr? Mind you, in this scenario, you should see a qWarning logged.

        Which Qt version are you using?

        SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @Paul-Colby good point, I forgot that the extension was implicit and thus thought about the other variants.

        @Creaperdown On that matter, are you sure that your resources properly embeds the translation file ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        C 1 Reply Last reply
        0
        • SGaistS SGaist

          @Paul-Colby good point, I forgot that the extension was implicit and thus thought about the other variants.

          @Creaperdown On that matter, are you sure that your resources properly embeds the translation file ?

          C Offline
          C Offline
          Creaperdown
          wrote on last edited by
          #5

          @SGaist i am pretty certain that the files are embedded into the application, since compiling and publishing it on windows works just fine.

          1 Reply Last reply
          0
          • Paul ColbyP Paul Colby

            Hi @Creaperdown,

            @SGaist said in QGuiApplication::installTranslator fails:

            It seems you are trying to use the full path to your translation files and that is the issue.

            I don't believe that's an issue. As per the doc's you linked:

            Loads filename ... which may be an absolute file name or relative to directory.

            Assuming that m_translator.load() did indeed succeed, then, just poking around the QCoreApplication::installTranslator() source, here's a few reasons I can see it might return false:

            1. &m_translator is nullptr (seems impossible in your case)
            2. m_translator.isEmpty() is true - easy enough for you to test.
            3. the current application instance is nullptr. ie have you made sure this code only runs after the app instance is constructed? Try checking if QCoreApplication::instance() is nullptr? Mind you, in this scenario, you should see a qWarning logged.

            Which Qt version are you using?

            C Offline
            C Offline
            Creaperdown
            wrote on last edited by Creaperdown
            #6

            @Paul-Colby I have changed my code to:

            bool AppInfoController::switchToLanguage(const QString& language)
            {
                if(!m_translator.isEmpty())
                    QGuiApplication::removeTranslator(&m_translator);
            
                auto success = m_translator.load(":/i18n/librum_" + language);
                if(!success)
                {
                    qWarning() << "Failed switching to language: " << language;
                    return false;
                }
            
                if(m_translator.isEmpty())
                {
                    qWarning() << "Translator is empty after successfully loading";
                    return false;
                }
            
                if(QCoreApplication::instance() == nullptr)
                {
                    qWarning() << "QCoreApplication is nullptr";
                    return false;
                }
            
                if(!QGuiApplication::installTranslator(&m_translator))
                {
                    qWarning() << "Failed installing translator for language: " << language;
                    return false;
                }
            
            
                emit languageChanged();
            
                // Use "English" for all kinds of English variants like American English
                if(QLocale(language).language() == QLocale::Language::English)
                    m_language = "English";
                else
                    m_language = QLocale(language).nativeLanguageName();
            
            
                QSettings settings;
                settings.setValue("language", language);
            
                m_engine->retranslate();
                return true;
            }
            

            And I can confirm that the translator.isEmpty() evaluates to true

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Creaperdown
              wrote on last edited by
              #7

              I have added debug output to the flatpack app to check the file size of the translation files and it seems like they do not get build correctly in that environment for some reason. They are only ~40 bytes in size.

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Creaperdown
                wrote on last edited by Creaperdown
                #8

                This is the build output. The .qm file generation looks fine from what I see.

                -- Build files have been written to: /run/build/librum-testing
                [1/95] Generating librum_de.qm
                Updating '/run/build/librum-testing/src/presentation/librum_de.qm'...
                    Generated 359 translation(s) (359 finished and 0 unfinished)
                [2/95] Generating librum_ru.qm
                Updating '/run/build/librum-testing/src/presentation/librum_ru.qm'...
                    Generated 359 translation(s) (359 finished and 0 unfinished)
                [3/95] Generating librum_en.qm
                Updating '/run/build/librum-testing/src/presentation/librum_en.qm'...
                    Generated 0 translation(s) (0 finished and 0 unfinished)
                    Ignored 359 untranslated source text(s)
                [5/95] cd /run/build/librum-testing/src/presentation && /usr/bin/cmake -DIN_FILE=/run/build/librum-test.../usr/bin/lupdate -project /run/build/librum-testing/src/presentation/.lupdate/presentation_project.json
                lupdate warning: Some files have been ignored due to missing qml/javascript support
                /usr/include/QtQml/qqmlprivate.h:343: Ignoring definition of undeclared qualified class
                /usr/include/QtQml/qqmlprivate.h:842: Ignoring definition of undeclared qualified class
                /usr/include/QtQml/qqmlprivate.h:856: Ignoring definition of undeclared qualified class
                /usr/include/QtQml/qqmlprivate.h:874: Ignoring definition of undeclared qualified class
                /usr/include/QtQml/qqmlprivate.h:888: Ignoring definition of undeclared qualified class
                /usr/include/QtQml/qqmlprivate.h:902: Ignoring definition of undeclared qualified class
                /usr/include/QtQml/qqmlprivate.h:917: Ignoring definition of undeclared qualified class
                /usr/include/QtQml/qqmlprivate.h:931: Ignoring definition of undeclared qualified class
                /usr/include/QtQml/qqmlprivate.h:945: Ignoring definition of undeclared qualified class
                Updating 'translations/librum_en.ts'...
                    Found 0 source text(s) (0 new and 0 already existing)
                    Kept 359 obsolete entries
                Updating 'translations/librum_de.ts'...
                    Found 0 source text(s) (0 new and 0 already existing)
                    Kept 359 obsolete entries
                Updating 'translations/librum_ru.ts'...
                    Found 0 source text(s) (0 new and 0 already existing)
                    Kept 359 obsolete entries
                
                Christian EhrlicherC 1 Reply Last reply
                0
                • C Creaperdown

                  This is the build output. The .qm file generation looks fine from what I see.

                  -- Build files have been written to: /run/build/librum-testing
                  [1/95] Generating librum_de.qm
                  Updating '/run/build/librum-testing/src/presentation/librum_de.qm'...
                      Generated 359 translation(s) (359 finished and 0 unfinished)
                  [2/95] Generating librum_ru.qm
                  Updating '/run/build/librum-testing/src/presentation/librum_ru.qm'...
                      Generated 359 translation(s) (359 finished and 0 unfinished)
                  [3/95] Generating librum_en.qm
                  Updating '/run/build/librum-testing/src/presentation/librum_en.qm'...
                      Generated 0 translation(s) (0 finished and 0 unfinished)
                      Ignored 359 untranslated source text(s)
                  [5/95] cd /run/build/librum-testing/src/presentation && /usr/bin/cmake -DIN_FILE=/run/build/librum-test.../usr/bin/lupdate -project /run/build/librum-testing/src/presentation/.lupdate/presentation_project.json
                  lupdate warning: Some files have been ignored due to missing qml/javascript support
                  /usr/include/QtQml/qqmlprivate.h:343: Ignoring definition of undeclared qualified class
                  /usr/include/QtQml/qqmlprivate.h:842: Ignoring definition of undeclared qualified class
                  /usr/include/QtQml/qqmlprivate.h:856: Ignoring definition of undeclared qualified class
                  /usr/include/QtQml/qqmlprivate.h:874: Ignoring definition of undeclared qualified class
                  /usr/include/QtQml/qqmlprivate.h:888: Ignoring definition of undeclared qualified class
                  /usr/include/QtQml/qqmlprivate.h:902: Ignoring definition of undeclared qualified class
                  /usr/include/QtQml/qqmlprivate.h:917: Ignoring definition of undeclared qualified class
                  /usr/include/QtQml/qqmlprivate.h:931: Ignoring definition of undeclared qualified class
                  /usr/include/QtQml/qqmlprivate.h:945: Ignoring definition of undeclared qualified class
                  Updating 'translations/librum_en.ts'...
                      Found 0 source text(s) (0 new and 0 already existing)
                      Kept 359 obsolete entries
                  Updating 'translations/librum_de.ts'...
                      Found 0 source text(s) (0 new and 0 already existing)
                      Kept 359 obsolete entries
                  Updating 'translations/librum_ru.ts'...
                      Found 0 source text(s) (0 new and 0 already existing)
                      Kept 359 obsolete entries
                  
                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  @Creaperdown said in QGuiApplication::installTranslator fails:

                  The .qm file generation looks fine from what I see.

                  But there are only translations for de and ru, the others are empty (= 40 bytes)

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  C 2 Replies Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    @Creaperdown said in QGuiApplication::installTranslator fails:

                    The .qm file generation looks fine from what I see.

                    But there are only translations for de and ru, the others are empty (= 40 bytes)

                    C Offline
                    C Offline
                    Creaperdown
                    wrote on last edited by
                    #10

                    @Christian-Ehrlicher thats right, there are only translations to de and ru, there also is one en file which is supposed to be empty

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      Creaperdown
                      wrote on last edited by
                      #11

                      If I stop the flatpak build process and inspect the files I can see this generally good looking translation file: https://ufile.io/yrvwy7sn (this is librum_de.qm)

                      1 Reply Last reply
                      0
                      • Christian EhrlicherC Christian Ehrlicher

                        @Creaperdown said in QGuiApplication::installTranslator fails:

                        The .qm file generation looks fine from what I see.

                        But there are only translations for de and ru, the others are empty (= 40 bytes)

                        C Offline
                        C Offline
                        Creaperdown
                        wrote on last edited by
                        #12

                        @Christian-Ehrlicher I have found something weird later on in the build process.

                        It seems to do the following:

                        • Generate the qm files from the ts files correctly
                        • Incorrectly updating the ts files (for what ever reason)
                        • Building the qm files again

                        This is the shortened output of the build process:

                        [Downloading the github repos...]
                        -- The CXX compiler identification is GNU 12.2.0
                        -- Detecting CXX compiler ABI info
                        -- Detecting CXX compiler ABI info - done
                        -- Check for working CXX compiler: /usr/bin/c++ - skipped
                        -- Detecting CXX compile features
                        -- Detecting CXX compile features - done
                        -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
                        -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
                        -- Found Threads: TRUE  
                        -- Performing Test HAVE_STDATOMIC
                        -- Performing Test HAVE_STDATOMIC - Success
                        -- Found WrapAtomic: TRUE  
                        -- Found OpenGL: /usr/lib/x86_64-linux-gnu/libOpenGL.so   
                        -- Found WrapOpenGL: TRUE  
                        -- Found XKB: /usr/lib/x86_64-linux-gnu/libxkbcommon.so (found suitable version "1.5.0", minimum required is "0.5.0") 
                        -- Found WrapVulkanHeaders: /usr/include  
                        -- Configuring done (0.7s)
                        -- Generating done (0.0s)
                        -- Build files have been written to: /run/build/librum-testing
                        [1/95] Generating librum_de.qm
                        Updating '/run/build/librum-testing/src/presentation/librum_de.qm'...
                            Generated 359 translation(s) (359 finished and 0 unfinished)
                        [2/95] Generating librum_en.qm
                        Updating '/run/build/librum-testing/src/presentation/librum_en.qm'...
                            Generated 0 translation(s) (0 finished and 0 unfinished)
                            Ignored 359 untranslated source text(s)
                        [3/95] Generating librum_ru.qm
                        Updating '/run/build/librum-testing/src/presentation/librum_ru.qm'...
                            Generated 359 translation(s) (359 finished and 0 unfinished)
                        [4/95] Running qmlimportscanner for librum
                        [5/95] cd /run/build/librum-testing/src/presentation && /usr/bin/cmake -DIN_FILE=/run/build/librum-testing/src/presentation/.lupdate/presentation_project.cmake -DOUT_FILE=/run/build/librum-testing/src/presentation/.lupdate/presentation_project.json -P /usr/lib/x86_64-linux-gnu/cmake/Qt6LinguistTools/GenerateLUpdateProject.cmake && /usr/bin/lupdate -project /run/build/librum-testing/src/presentation/.lupdate/presentation_project.json
                        lupdate warning: Some files have been ignored due to missing qml/javascript support
                        /usr/include/QtQml/qqmlprivate.h:343: Ignoring definition of undeclared qualified class
                        /usr/include/QtQml/qqmlprivate.h:842: Ignoring definition of undeclared qualified class
                        /usr/include/QtQml/qqmlprivate.h:856: Ignoring definition of undeclared qualified class
                        /usr/include/QtQml/qqmlprivate.h:874: Ignoring definition of undeclared qualified class
                        /usr/include/QtQml/qqmlprivate.h:888: Ignoring definition of undeclared qualified class
                        /usr/include/QtQml/qqmlprivate.h:902: Ignoring definition of undeclared qualified class
                        /usr/include/QtQml/qqmlprivate.h:917: Ignoring definition of undeclared qualified class
                        /usr/include/QtQml/qqmlprivate.h:931: Ignoring definition of undeclared qualified class
                        /usr/include/QtQml/qqmlprivate.h:945: Ignoring definition of undeclared qualified class
                        Updating 'translations/librum_en.ts'...
                            Found 0 source text(s) (0 new and 0 already existing)
                            Kept 359 obsolete entries
                        Updating 'translations/librum_de.ts'...
                            Found 0 source text(s) (0 new and 0 already existing)
                            Kept 359 obsolete entries
                        Updating 'translations/librum_ru.ts'...
                            Found 0 source text(s) (0 new and 0 already existing)
                            Kept 359 obsolete entries
                        [6/95] Automatic MOC and UIC for target domain
                        [7/95] Building CXX object src/domain/CMakeFiles/domain.dir/value_objects/login_model.cpp.o
                        [8/95] Building CXX object src/domain/CMakeFiles/domain.dir/value_objects/register_model.cpp.o
                        [9/95] Building CXX object src/domain/CMakeFiles/domain.dir/entities/tag.cpp.o
                        [10/95] Building CXX object src/domain/CMakeFiles/domain.dir/entities/bookmark.cpp.o
                        [11/95] Building CXX object src/domain/CMakeFiles/domain.dir/domain_autogen/mocs_compilation.cpp.o
                        [12/95] Building CXX object src/domain/CMakeFiles/domain.dir/entities/rectf.cpp.o
                        [13/95] Building CXX object src/domain/CMakeFiles/domain.dir/entities/user.cpp.o
                        [14/95] Building CXX object src/domain/CMakeFiles/domain.dir/entities/highlight.cpp.o
                        [15/95] Building CXX object src/domain/CMakeFiles/domain.dir/entities/book.cpp.o
                        [16/95] Linking CXX shared library libdomain.so
                        [17/95] Building mupdf (This takes a while) ...
                        [A lot of output from building a dependency...]
                        [18/95] Automatic MOC and UIC for target application
                        [Building librum...]
                        [86/95] Building CXX object src/presentation/CMakeFiles/presentation.dir/presentation_autogen/mocs_compilation.cpp.o
                        [87/95] Building CXX object src/presentation/CMakeFiles/presentation.dir/modules/CppElements/page_view.cpp.o
                        [88/95] Building CXX object src/presentation/CMakeFiles/presentation.dir/presentation_autogen/YCDLW3T4OG/qrc_resources.cpp.o
                        [89/95] Linking CXX shared library libpresentation.so
                        [90/95] Automatic MOC and UIC for target librum
                        [91/95] Automatic RCC for ../fonts.qrc
                        [92/95] Building CXX object src/CMakeFiles/librum.dir/librum_autogen/mocs_compilation.cpp.o
                        [93/95] Building CXX object src/CMakeFiles/librum.dir/librum_autogen/YCDLW3T4OG/qrc_fonts.cpp.o
                        [94/95] Building CXX object src/CMakeFiles/librum.dir/main.cpp.o
                        [95/95] Linking CXX executable librum
                        [1/13] Generating librum_en.qm
                        Updating '/run/build/librum-testing/src/presentation/librum_en.qm'...
                            Generated 0 translation(s) (0 finished and 0 unfinished)
                        [2/13] Generating librum_ru.qm
                        Updating '/run/build/librum-testing/src/presentation/librum_ru.qm'...
                            Generated 0 translation(s) (0 finished and 0 unfinished)
                        [3/13] Generating librum_de.qm
                        Updating '/run/build/librum-testing/src/presentation/librum_de.qm'...
                            Generated 0 translation(s) (0 finished and 0 unfinished)
                        [4/13] cd /run/build/librum-testing/src/presentation && /usr/bin/cmake -DIN_FILE=/run/build/librum-testing/src/presentation/.lupdate/presentation_project.cmake -DOUT_FILE=/run/build/librum-testing/src/presentation/.lupdate/presentation_project.json -P /usr/lib/x86_64-linux-gnu/cmake/Qt6LinguistTools/GenerateLUpdateProject.cmake && /usr/bin/lupdate -project /run/build/librum-testing/src/presentation/.lupdate/presentation_project.json
                        lupdate warning: Some files have been ignored due to missing qml/javascript support
                        /usr/include/QtQml/qqmlprivate.h:343: Ignoring definition of undeclared qualified class
                        /usr/include/QtQml/qqmlprivate.h:842: Ignoring definition of undeclared qualified class
                        /usr/include/QtQml/qqmlprivate.h:856: Ignoring definition of undeclared qualified class
                        /usr/include/QtQml/qqmlprivate.h:874: Ignoring definition of undeclared qualified class
                        /usr/include/QtQml/qqmlprivate.h:888: Ignoring definition of undeclared qualified class
                        /usr/include/QtQml/qqmlprivate.h:902: Ignoring definition of undeclared qualified class
                        /usr/include/QtQml/qqmlprivate.h:917: Ignoring definition of undeclared qualified class
                        /usr/include/QtQml/qqmlprivate.h:931: Ignoring definition of undeclared qualified class
                        /usr/include/QtQml/qqmlprivate.h:945: Ignoring definition of undeclared qualified class
                        Updating 'translations/librum_en.ts'...
                            Found 0 source text(s) (0 new and 0 already existing)
                        Updating 'translations/librum_de.ts'...
                            Found 0 source text(s) (0 new and 0 already existing)
                        Updating 'translations/librum_ru.ts'...
                            Found 0 source text(s) (0 new and 0 already existing)
                        [5/13] Building mupdf (This takes a while) ...
                        [Building the dependency that we have built before again...]
                        [6/10] Running rcc for resource presentation_translations
                        [7/10] Building CXX object src/presentation/CMakeFiles/presentation.dir/.rcc/qrc_presentation_translations.cpp.o
                        [8/10] Linking CXX shared library libpresentation.so
                        [9/10] Linking CXX executable librum
                        [9/10] Install the project...
                        -- Install configuration: "Release"
                        -- Installing: /app/lib/libdomain.so
                        -- Installing: /app/lib/libapplication.so
                        -- Set runtime path of "/app/lib/libapplication.so" to ""
                        -- Installing: /app/lib/libmupdfcpp.so
                        -- Installing: /app/lib/libmupdf.so
                        -- Installing: /app/lib/libmupdfcpp.so.24.0
                        -- Installing: /app/lib/libmupdf.so.24.0
                        -- Installing: /app/lib/libinfrastructure.so
                        -- Set runtime path of "/app/lib/libinfrastructure.so" to ""
                        -- Installing: /app/lib/libadapters.so
                        -- Set runtime path of "/app/lib/libadapters.so" to ""
                        -- Installing: /app/lib/libpresentation.so
                        -- Set runtime path of "/app/lib/libpresentation.so" to ""
                        -- Installing: /app/bin/librum
                        -- Set runtime path of "/app/bin/librum" to ""
                        -- Installing: /app/share/pixmaps/librum.svg
                        -- Installing: /app/share/applications/librum.desktop
                        [Some cleanup...]
                        
                        

                        I have no idea why it starts at [1/13] again, but I suppose that this causes the problem since it overwrites the seemingly correct qm files.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved