Solved Check for QTranslator::load
-
@mrjj ok thank you
-
-
@Pablo-J-Rogina yeah I forgot to do that
-
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.
-
Hi,
Can you show your .pro file and the way you use QTranslator ?
-
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); }
-
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.
-
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.
-
Ok, can you show your .qrc file ?
-
-
Can you show it's text content ?
-
This post is deleted! -
No, the .qrc raw content.
-
-
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.
-
@SGaist I checked them and they are working fine but after deployment they don't unless I add .qm file to the directory.
-
Did you try to list the content of the .qrc file using QDir at run time just to ensure you have everything in place ?
-
@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. -
@SGaist said in Check for QTranslator::load:
Did you try to list the content of the .qrc file using QDir at run time just to ensure you have everything in place ?
I will do that and get back to you
-
@nagesh but I am loading from resource file, it shouldn't care for the directory of the .qm file in the deployment since the resource files are supposed to be compiled into the .exe file