Different QLocale's used for different windows

  • I have a retranslatable application and two top level windows - the main application window and a dialog. The problem is that the dialog doesn't use the system's locale as the main window does but it depends on the locale introduced by the currently installed translator. Let's say you have the following situation:

    1. there is a QDoubleSpinBox in the main window and in the dialog
    2. the regional and language settings are set to use United States formatting, etc.
    3. currently a Bulgarian translation "bg_BG" is installed through a translator where the decimal point is comma ',' not a dot '.'

    In this case the QDoubleSpinBox in the main window will display the floating point value using '.' (US English notation) as decimal point separator, whereas the dialog, which uses the locale of the currently installed translator, will use ','.
    First, which locale should be used by the application's windows - the system one, the installed translator's one, or?
    Next thing. The dialog is lazily created upon request. It uses the locale of the translator installed at the time of its creation. Then after changing languages dynamically the dialog does not apply the new translator's locale. So, if the locale is changed and the application is restarted and then the last used translation is loaded upon application start, when the dialog is launched it then starts using the last introduced locale.

  • Found the source of the problem but I am still totally confused which locale should the application use - the translator's one or the system's one. The problem was that I created the content of the dialog as:

    class SomeDialog : public QDialog
            QWidget* const dlgContent = new QWidget;
            QVBoxLayout* const mainLayout = new QVBoxLayout( this );
            mainLayout->addWidget( dlgContent );

    Where I didn't provide an initial parent for the dlgContent, since the layout would parent the dlgContent to this and I usually do not directly parent widgets upon creation, so that to avoid further reparenting. So initial parenting solves the problem:

    QWidget* const dlgContent = new QWidget( this );

    Again the second main question remains unanswered.

  • Actually this partially fixes the things. Now using English (US) regional and language settings and having Deutsch as application language, the first time the dialog is launched the decimal point separator is dot in some places and comma in other controls of the dialog. Reopening the dialog all controls start using the comma as a decimal point separator which is not the separator for both English (US) and German (Germany) locales.

Log in to reply

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