how to clear QTranslator
-
@SGaist said in how to clear QTranslator:
Are you re-creating the translator at some point ?
yes, as i mentioned i have a translator from the main and created another translator from another class. In another class i loaded the file that is currently installed based on the stored language.
-
Then aren't you trying to remove a translator that wasn't installed in the first place ?
-
The problem is if
&translator
used in installTranslator is the same as&translator
used in removeTranslator. where does translator live. if it's a local variable you are doing it wrong@VRonin said in how to clear QTranslator:
The problem is if
&translator
used in installTranslator is the same as&translator
used in removeTranslator. where does translator live. if it's a local variable you are doing it wrongShouldn't that be the case? if you remove the previously installed translator, that is also what you need to pass for it to uninstall?
The translator in other class is private.
-
What I mean is:
Wrong:
{ QTranslator translator; translator.load("translation_de_DE", location); qApp -> installTranslator(&translator); } { QTranslator translator; qApp -> removeTranslator(&translator); }
Right:
QTranslator translator; { translator.load("translation_de_DE", location); qApp -> installTranslator(&translator); } { qApp -> removeTranslator(&translator); }
We'd need to see where
translator
is declared and from where do you call those functions to help you better -
What I mean is:
Wrong:
{ QTranslator translator; translator.load("translation_de_DE", location); qApp -> installTranslator(&translator); } { QTranslator translator; qApp -> removeTranslator(&translator); }
Right:
QTranslator translator; { translator.load("translation_de_DE", location); qApp -> installTranslator(&translator); } { qApp -> removeTranslator(&translator); }
We'd need to see where
translator
is declared and from where do you call those functions to help you better@VRonin osrry, it isn't declared locally on the function. I have declared the it in the header file.
//Settings.h class Settings : public QObject { QTranslator translator; } // Settings.cpp Settings::Settings(QObject *parent) : QObject (parent) { loadTranslator(Profile::Language); }
-
@VRonin osrry, it isn't declared locally on the function. I have declared the it in the header file.
//Settings.h class Settings : public QObject { QTranslator translator; } // Settings.cpp Settings::Settings(QObject *parent) : QObject (parent) { loadTranslator(Profile::Language); }
-
@literA2 then what is the life cycle of
Settings
instance(s)?
is loadTranslator a global function? -
You should also check that
translator.load
runs successfully