Use qApp
qApp->loadTranslator();
Use qApp
qApp->loadTranslator();
The biggest difference between time and space is that you can't reuse time.
-- Merrick Furst
Hmm, this does not work:Qt Code:
void CLanguageSelectorWidget::translateSlovene() { m_Translator.load("translations/eROSystem_client_SL"); // loads translator //QApplication::installTranslator(&m_Translator); // installs it qApp->installTranslator(&m_Translator); // installs it emit accept(); // closes window }To copy to clipboard, switch view to plain text mode
Why not???
In main.cpp there is a very similar code that works:Qt Code:
// translator setup QTranslator qtTranslator; qtTranslator.load("translations/eROSystem_client_SL"); a.installTranslator(&qtTranslator);To copy to clipboard, switch view to plain text mode
Why the upper code chunk does not work?? Signals/Slots are ok, I've checked.
Qt 5.3 Opensource & Creator 3.1.2
In main() the QTranslator object remains alive because QApplication::exec() blocks until the application quits. Is CLanguageSelectorWidget allocated on the stack? The translator object goes out of scope as soon as CLanguageSelectorWidget is destructed.
J-P Nurmi
How come, if m_Translator is defined in its header file:Qt Code:
#ifndef CLANGUAGESELECTORWIDGET_H_ #define CLANGUAGESELECTORWIDGET_H_ /*! * \class CLanguageSelectorWidget * \author VSistemi Marko Frelih s.p. * \version 1.0 * \date January 2007 * \brief This Qt based class represents a language selector widget, which constist of number of * CFlagButton objects. * \details version 1.00 (revision 84): basic functionality */ // qt includes #include <QDialog> #include <QHBoxLayout> #include <QVBoxLayout> #include <QList> #include <QFont> #include <QPalette> #include <QTranslator> #include <QApplication> class QWidget; // forward declaration // custom includes #include "CFlagButton.h" { Q_OBJECT public: ~CLanguageSelectorWidget(); inline QPointer<QHBoxLayout> langaugeButtonsLayout() { return m_pLanguageButtonsLayout; }; inline QPointer<QVBoxLayout> mainLayout() { return m_pMainLayout; }; //inline QList<CFlagButton> languageButtonsList() { return mLanguageButtonsList; }; inline QPointer<QPushButton> sloLangButton() { return m_pSloLangButton; }; inline QPointer<QPushButton> ukLangButton() { return m_pUKLangButton; }; inline QPointer<QPushButton> deuLangButton() { return m_pDeuLangButton; }; inline QPointer<QPushButton> itaLangButton() { return m_pItaLangButton; }; public: // TODO: this member should be private //QList<CFlagButton> mLanguageButtonsList; // language buttons list private: QPointer<QHBoxLayout> m_pLanguageButtonsLayout; // horizontal layout QPointer<QVBoxLayout> m_pMainLayout; // main layouts QPointer<QPushButton> m_pSloLangButton; // slo lang QPointer<QPushButton> m_pUKLangButton; // eng lang QPointer<QPushButton> m_pDeuLangButton; // deu lang QPointer<QPushButton> m_pItaLangButton; // ita lang QPalette m_WidgetPalette; // widget palette QTranslator m_Translator; // application translator private slots: void translateSlovene(); // launches slovenian translation void translateEnglish(); // launches english translation void translateDeutsch(); // launches german translation void translateItaliano(); // launches italian translation }; #endif /*CLANGUAGESELECTORWIDGET_H_*/To copy to clipboard, switch view to plain text mode
Qt 5.3 Opensource & Creator 3.1.2
Where do you show/exec CLanguageSelectorWidget? Consider following code:
Qt Code:
{ CLanguageSelectorWidget dialog(this); { } } // the translator gets destructed here together with CLanguageSelectorWidgetTo copy to clipboard, switch view to plain text mode
J-P Nurmi
So, what do you suggest, how should I recode?
Qt 5.3 Opensource & Creator 3.1.2
Allocate the translator on the heap. In other words, create the translator with keyword "new". It must remain alive after the dialog gets destructed, right?
J-P Nurmi
Yes, you are right. God damn, I've forgot the basics ... I've allocated it, but same result. I think object gets destructed again after leaving QDialog:Qt Code:
Q_CHECK_PTR(m_pTranslator); // checks creation m_pTranslator->load("translations/eROSystem_client_ITA"); // loads translator //QApplication::installTranslator(&m_Translator); // installs it qApp->installTranslator(m_pTranslator); // installs it emit accept(); // closes windowTo copy to clipboard, switch view to plain text mode
Am I right?
Qt 5.3 Opensource & Creator 3.1.2
Don't pass "this" as its parent. Every QObject will automatically delete its children. Here, the dialog will delete the translator. Try passing for example "qApp" as parent instead.
J-P Nurmi
I did, still no result. Is it possible the path to translator file is corrupted??? Is it ok to use "/" in path under windows instead of "\'
Qt 5.3 Opensource & Creator 3.1.2
QTranslator::load() returns true if the translation is successfully loaded; otherwise returns false. So check the return value!
Yes, it's ok. Qt will translate your paths to conform to the underlying operating system.Is it ok to use "/" in path under windows instead of "\'
J-P Nurmi
Here is the code:Every language button succesfully loads translator. But still no result!!!Qt Code:
Q_CHECK_PTR(m_pTranslator); // checks creation if(m_pTranslator->load("translations/eROSystem_client_ITA")) // loads translator { //QApplication::installTranslator(&m_Translator); // installs it qApp->installTranslator(m_pTranslator); // installs it emit accept(); // closes window, success } else { emit reject(); // failure }To copy to clipboard, switch view to plain text mode![]()
Qt 5.3 Opensource & Creator 3.1.2
Bookmarks