Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Translating after QSetting is used to determine last state
Forum Updated to NodeBB v4.3 + New Features

Translating after QSetting is used to determine last state

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 4.2k Views 1 Watching
  • 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 Offline
    S Offline
    soroush
    wrote on last edited by
    #1

    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
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      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
      0
      • S Offline
        S Offline
        soroush
        wrote on last edited by
        #3

        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
        0
        • L Offline
          L Offline
          loladiro
          wrote on last edited by
          #4

          Where are you constructing Configuration::settings?

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

          1 Reply Last reply
          0
          • S Offline
            S Offline
            soroush
            wrote on last edited by
            #5

            bq. %1: Unknown error %2

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

            1 Reply Last reply
            0
            • L Offline
              L Offline
              loladiro
              wrote on last edited by
              #6

              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
              0
              • S Offline
                S Offline
                soroush
                wrote on last edited by
                #7

                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
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved