Translating after QSetting is used to determine last state
-
Hi
I need to read a value from QSettings specifying the last UI language that user used:
@
QApplication app(argc, argv);
Configuration::createInstance();
Configuration::Language lang =
(Configuration::Language)Configuration::settings->value("language").value<int>();
if(lang == Configuration::Persian)
{
QTranslator qtTranslation;
qApp->installTranslator(&qtTranslation);
}
@
I got this warning in runtime
@
KGlobal::locale::Warning your global KLocale is being recreated with a valid main component instead of a fake component, this usually means you tried to call i18n related functions before your main component was created. You should not do that since it most likely will not work
@
and translation is not done. but when remove QSettings and QTranslator became immediately after QApplication, everything works. I mean this:
@
QApplication app(argc, argv);
//Configuration::Language lang =
// (Configuration::Language)Configuration::settings->value("language").value<int>();
//if(lang == Configuration::Persian)
//{
QTranslator qtTranslation;
qApp->installTranslator(&qtTranslation);
//}@What's happening here? Should translation be the first thing I do in program? why?
-
I think the problem may be, that your Configuration class is static. At least, it looks that way from the code snippet you provide. That means that it is constructed, along with the QSettings I guess it contains, before the QApplication is constructed. Could you show what your Configuration class looks like?
-
Configuration class:
@
#ifndef CONFIGURATION_H
#define CONFIGURATION_H#include <QSettings>
class Configuration
{
public:
explicit Configuration();
static QSettings *settings;
static void createInstance();
enum Language{English,Persian};
};
// configuration.cpp:
#include "configuration.h"QSettings* Configuration::settings;
Configuration::Configuration()
{
}void Configuration::createInstance()
{
Configuration::settings = new QSettings("","program");
}#endif // CONFIGURATION_H
@ -
You could try to debug. From KGlobal.cpp
@
00173 // If you hit the warning below, here's how to debug it in gdb:
00174 // (gdb) set auto-solib-add on
00175 // (gdb) b qt_message_output
00176 // (gdb) run
00177 // It will stop at the "-nograb" information.
00178 // (gdb) b KLocalePrivate::KLocalePrivate
00179 // (gdb) c
00180 // And now it will stop at the first construction of the KLocale object, type bt or go up to find the
00181 // guilty i18n call.
@