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. Check for QTranslator::load
Forum Updated to NodeBB v4.3 + New Features

Check for QTranslator::load

Scheduled Pinned Locked Moved Solved General and Desktop
25 Posts 6 Posters 3.0k 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.
  • H Offline
    H Offline
    hbatalha
    wrote on last edited by
    #1

    I have an application where I need to internationalize it.
    I have already set up everything and all is working fine. The QTranslator objects all load from the resource file.

    What I want to know is that if I need to check the result of each QTranslator object load operation before installing a translator.

    I guessing that since all the resource files are compiled into executable file I don't need this check beforeinstalling a translator. But I am not sure.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      When in a resource its unlikely it would fail but
      say you misspelled the filename, later on, it might be nice
      if the code would catch it and show an error.

      I would check it as it might work for a long time but
      then someone changes a filename or similar, and its
      a frustration if it then "just don't work" and the user cannot report
      any errors or indication of that went wrong.

      H 1 Reply Last reply
      1
      • H Offline
        H Offline
        hbatalha
        wrote on last edited by
        #3

        @mrjj ok thank you

        Pablo J. RoginaP 1 Reply Last reply
        0
        • H hbatalha

          @mrjj ok thank you

          Pablo J. RoginaP Offline
          Pablo J. RoginaP Offline
          Pablo J. Rogina
          wrote on last edited by
          #4

          @hbatalha did that reply from @mrjj solve your issue/doubt?
          If so please don't forget to mark your post as solved!

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          H 1 Reply Last reply
          1
          • Pablo J. RoginaP Pablo J. Rogina

            @hbatalha did that reply from @mrjj solve your issue/doubt?
            If so please don't forget to mark your post as solved!

            H Offline
            H Offline
            hbatalha
            wrote on last edited by
            #5

            @Pablo-J-Rogina yeah I forgot to do that

            1 Reply Last reply
            0
            • mrjjM mrjj

              Hi
              When in a resource its unlikely it would fail but
              say you misspelled the filename, later on, it might be nice
              if the code would catch it and show an error.

              I would check it as it might work for a long time but
              then someone changes a filename or similar, and its
              a frustration if it then "just don't work" and the user cannot report
              any errors or indication of that went wrong.

              H Offline
              H Offline
              hbatalha
              wrote on last edited by hbatalha
              #6

              @mrjj

              When in a resource its unlikely it would fail

              Well , it seems that it just failed me or I am doing something wrong. I just deployed my application with windeployqt and the resulting .exe doesn't translate the ui unless I add the .qm file to the same directory as I do when I compile my app.

              I thought that all the files in the resource file are be compiled into the .exe but it is not happening with the .qm file as all the other files added in the resource seem to be working fine.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi,

                Can you show your .pro file and the way you use QTranslator ?

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

                H 1 Reply Last reply
                1
                • SGaistS SGaist

                  Hi,

                  Can you show your .pro file and the way you use QTranslator ?

                  H Offline
                  H Offline
                  hbatalha
                  wrote on last edited by hbatalha
                  #8

                  @SGaist

                  QT       += core gui
                  QT       += network
                  
                  win32 {
                      LIBS += -lwininet
                  }
                  
                  greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
                  
                  CONFIG += c++11
                  
                  # You can make your code fail to compile if it uses deprecated APIs.
                  # In order to do so, uncomment the following line.
                  #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
                  
                  SOURCES += \
                      about.cpp \
                      main.cpp \
                      mainwindow.cpp \
                      settings.cpp 
                  
                  HEADERS += \
                      about.h \
                      mainwindow.h \
                      settings.h 
                  
                  FORMS += \
                      about.ui \
                      mainwindow.ui \
                      settings.ui 
                  
                  # Default rules for deployment.
                  qnx: target.path = /tmp/$${TARGET}/bin
                  else: unix:!android: target.path = /opt/$${TARGET}/bin
                  !isEmpty(target.path): INSTALLS += target
                  
                  RESOURCES += \
                      resources.qrc
                  
                  TRANSLATIONS += Languages/transl_portuguese.ts
                  

                  mainwindow.cpp

                  MainWindow::MainWindow(QWidget *parent)
                      : QMainWindow(parent)
                      , ui(new Ui::MainWindow)
                  {
                      ui->setupUi(this);
                  
                      if( ! translatorPt.load(":/Languages/transl_portuguese.qm"))
                          qDebug() << "not loaded";
                  
                  ...
                  }
                  
                  void MainWindow::updateLanguage()
                  {
                      if(preferences.language == Preferences::Language::ENGLISH)
                          qApp->removeTranslator(&translatorPt);
                      else if(preferences.language == Preferences::Language::PORTUGUESE)
                          qApp->installTranslator(&translatorPt);
                  }
                  
                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    You .pro file has issues, you have several times line endings with a backslash that should not. When listing files vertically, the last one should not have that line.

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

                    H 1 Reply Last reply
                    1
                    • SGaistS SGaist

                      You .pro file has issues, you have several times line endings with a backslash that should not. When listing files vertically, the last one should not have that line.

                      H Offline
                      H Offline
                      hbatalha
                      wrote on last edited by hbatalha
                      #10

                      @SGaist

                      you have several times line endings with a backslash that should not

                      That was a mistake of mine, I deleted some commented lines and I missed those backslashes , I will edit the post.

                      The edited post is now as my .pro file I am using in the program.

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        Ok, can you show your .qrc file ?

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

                        H 1 Reply Last reply
                        0
                        • SGaistS SGaist

                          Ok, can you show your .qrc file ?

                          H Offline
                          H Offline
                          hbatalha
                          wrote on last edited by
                          #12

                          @SGaist Screenshot_1.png

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            Can you show it's text content ?

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

                            H 1 Reply Last reply
                            0
                            • SGaistS SGaist

                              Can you show it's text content ?

                              H Offline
                              H Offline
                              hbatalha
                              wrote on last edited by
                              #14
                              This post is deleted!
                              1 Reply Last reply
                              0
                              • SGaistS Offline
                                SGaistS Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on last edited by
                                #15

                                No, the .qrc raw content.

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

                                H 1 Reply Last reply
                                0
                                • SGaistS SGaist

                                  No, the .qrc raw content.

                                  H Offline
                                  H Offline
                                  hbatalha
                                  wrote on last edited by
                                  #16

                                  @SGaist
                                  Screenshot_2.png

                                  1 Reply Last reply
                                  0
                                  • SGaistS Offline
                                    SGaistS Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #17

                                    From there it looks all good.

                                    Just for the sake of debugging, you should check the install and remove calls since they return a Boolean.

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

                                    H 1 Reply Last reply
                                    0
                                    • SGaistS SGaist

                                      From there it looks all good.

                                      Just for the sake of debugging, you should check the install and remove calls since they return a Boolean.

                                      H Offline
                                      H Offline
                                      hbatalha
                                      wrote on last edited by
                                      #18

                                      @SGaist I checked them and they are working fine but after deployment they don't unless I add .qm file to the directory.

                                      1 Reply Last reply
                                      0
                                      • SGaistS Offline
                                        SGaistS Offline
                                        SGaist
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #19

                                        Did you try to list the content of the .qrc file using QDir at run time just to ensure you have everything in place ?

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

                                        H 2 Replies Last reply
                                        0
                                        • nageshN Offline
                                          nageshN Offline
                                          nagesh
                                          wrote on last edited by
                                          #20

                                          @hbatalha
                                          I feel you missed the second argument for the load function which is the directory path, where as first is the filename.

                                          translatorPt.load(":/Languages/transl_portuguese.qm"))
                                          

                                          If directory is not specified, the current directory is used (i.e., as currentPath()).
                                          So in deployment it will search for current path for the .qm file.

                                          H 1 Reply Last reply
                                          1

                                          • Login

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