Localization of text messages during main() function
-
Sometimes errors will occur before the main window is shown, or possibly warnings which can be shown just after calling
QMainWindow::show()
. However, I have not yet been able to show localized error messages except within the body of a function belonging to a descendent of QObject. I can translate them im QtLinguist, but only the original language is shown.Is there a well-known workaround for this? I suppose I could make them member variables in my main window class and defer showing the messages until after the main window opens, but maybe there is another way?
-
Sometimes errors will occur before the main window is shown, or possibly warnings which can be shown just after calling
QMainWindow::show()
. However, I have not yet been able to show localized error messages except within the body of a function belonging to a descendent of QObject. I can translate them im QtLinguist, but only the original language is shown.Is there a well-known workaround for this? I suppose I could make them member variables in my main window class and defer showing the messages until after the main window opens, but maybe there is another way?
@Robert-Hairgrove
Assuming what you say aboutQObject
is correct (I don't know), you don't have to wait for the declaration/creation/showing ofQMainWindow
to use that. For example, you might put up aQDialog
before/without even having aQMainWindow
. So that cannot be the issue, -
Sometimes errors will occur before the main window is shown, or possibly warnings which can be shown just after calling
QMainWindow::show()
. However, I have not yet been able to show localized error messages except within the body of a function belonging to a descendent of QObject. I can translate them im QtLinguist, but only the original language is shown.Is there a well-known workaround for this? I suppose I could make them member variables in my main window class and defer showing the messages until after the main window opens, but maybe there is another way?
@Robert-Hairgrove you can install a QTranslator and set the desired language even in main.cpp see this example...
#include <QApplication> #include <QPushButton> #include <QTranslator> int main(int argc, char *argv[]) { QApplication app(argc, argv); QTranslator translator; translator.load("hellotr_la"); app.installTranslator(&translator); QPushButton hello(QPushButton::tr("Hello world!")); hello.resize(100, 30); hello.show(); return app.exec(); }
-
Thanks ... the problem was that my translations were being updated to a different location. Now it is working!