Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Translating after QSetting is used to determine last state

    General and Desktop
    3
    7
    3717
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      soroush last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • A
        andre last edited by

        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?

        1 Reply Last reply Reply Quote 0
        • S
          soroush last edited by

          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
          @

          1 Reply Last reply Reply Quote 0
          • L
            loladiro last edited by

            Where are you constructing Configuration::settings?

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

            1 Reply Last reply Reply Quote 0
            • S
              soroush last edited by

              bq. %1: Unknown error %2

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

              1 Reply Last reply Reply Quote 0
              • L
                loladiro last edited by

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

                1 Reply Last reply Reply Quote 0
                • S
                  soroush last edited by

                  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.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post