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
    @



  • Where are you constructing Configuration::settings?

    EDIT: To clarify, I mean where are you calling createInstance to construct Configuration::settings.



  • bq. %1: Unknown error %2

    After line #1 of first code. I edited my code :-P



  • 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.
    @



  • In the "Application Output" panel :
    @&"warning: GDB: Failed to set controlling terminal: Invalid argument\n"@

    I don't know how to use debuggers. will take a look at documentation of gdb and come back.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.