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. Global Locales doesnt work for everything
Qt 6.11 is out! See what's new in the release blog

Global Locales doesnt work for everything

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 3 Posters 1.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.
  • Fuel 0F Offline
    Fuel 0F Offline
    Fuel 0
    wrote on last edited by
    #1

    Hey,

    to explain it shortly. I set this in my main.cpp File.

    QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates));
    

    So that my whole Project is in English. But there are some Party of my App that are still in German. Mostly the Dateformats like here.
    Unbenannt.png

    Normally it should show Dec and not Dez. I have to say that this is a special Widget and i already tried to set Locales in the Widget itself.

    Someone can help me? I thought Locales will be set Applicationwide.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Can you provide a minimal compilable example that shows that issue ?

      What version of Qt are you using ?
      On what OS ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Fuel 0F Offline
        Fuel 0F Offline
        Fuel 0
        wrote on last edited by Fuel 0
        #3

        I cant share everything at the Moment, but i will try to explain my Code. First, im using Qt 5.12.6 and im on Windows 10.

        In the Picture you see a QTableView Item and this TableView has a Model with this Data Method.

        QVariant DiaryTableModel::data(const QModelIndex &index, int role) const
        {
            if (!index.isValid())
                return QVariant();
        
            if (role == Qt::DisplayRole)
            {
                if (index.column() == 0)
                    return mItems.at(index.row())->date.toString("d. MMM yyyy");
                else if (index.column() == 2)
                    return mItems.at(index.row())->plain;
                else if (index.column() == 3)
                    return mItems.at(index.row())->tags;
                else if (index.column() == 4)
                    return mItems.at(index.row())->createdAt.toString("d. MMM yyyy");
                else if (index.column() == 5)
                    return mItems.at(index.row())->updatedAt.toString("d. MMM yyyy");
            }
            if (index.column() == 1)
                return QVariant::fromValue(mItems.at(index.row())->rating);
        
            return QVariant();
        }
        

        The Model is set in a Widget like this.

        mDiaryTable = new QTableView(this);
            mDiaryTable->setStyleSheet("QTableView { margin-bottom: 5px; border: 1px solid black; }"
                                       "QTableView:active { color: black; }"
                                       "QHeaderView::section { background-color: rgba(22, 15, 42, 1); color: white; }");
            mDiaryModel = new DiaryTableModel(this);
            mDiaryTable->setModel(mDiaryModel);
        

        The Widget that im using is a Widget that inherits from QWidget. And i use the Widget like this in the MainWindow.

        this->_wDiary.reset(new DiaryWidget());
        

        wDiary is a SharedPointer.

        Maybe the Problem is that the DiaryWidget is not a Child from the Parent MainWindow? But why i can set the Locales in the DiaryWidget. When i pass this to DiaryWidget(this) then the Widget is not shown correctly.

        Update:

        I tried to set the QTableView to the Locales with

        mDiaryTable->setLocale(QLocale(QLocale::English, QLocale::UnitedStates));
        

        that also doesnt work.

        1 Reply Last reply
        0
        • Fuel 0F Offline
          Fuel 0F Offline
          Fuel 0
          wrote on last edited by
          #4

          Nobody has a Tipp what i can looking for? Dont know how to solve this or what i need to search for in the Internet. Its weird that my QTableView does not use the Applicationwide setup.

          1 Reply Last reply
          0
          • Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Please provide a minimal testcase to reproduce the issue. The issue you're seeing can have many reasons.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            0
            • Fuel 0F Offline
              Fuel 0F Offline
              Fuel 0
              wrote on last edited by
              #6

              I tried to create a new Project and removed everything unnecessary. Still the same Problem. I uploaded it in Github, so you can try it.
              At the Moment you cant insert Data to the Project in the Application. You need to start the Application so the Sqlite Database will be created and then you need to insert data.

              https://github.com/FuelKubitox/KubitoxLeartTest

              1 Reply Last reply
              0
              • Christian EhrlicherC Online
                Christian EhrlicherC Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                This doesn't look like a minimal example. Please try to reproduce it with a single view + model.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                1
                • Fuel 0F Offline
                  Fuel 0F Offline
                  Fuel 0
                  wrote on last edited by
                  #8

                  The Project is reduced to minimum. Without the other Things the Table doesnt work correctly. I can remove the Delegate and some Things from the Desing, but thats all. @Christian-Ehrlicher I mean, if you want to run the Code, why you dont clone the Repository and run it? Im happy that someone has the Will to help, but i already reduced the Project and create a new Repository. For a Single View with Model i have to create a new Project and code everything from Start. Maybe with copy and pasting, but why should i do that if i expose everything in a Repository?

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Online
                    Christian EhrlicherC Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    I was looking for something like this:

                    int main(int argc, char **argv)
                    {
                        QApplication app(argc, argv);
                        QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates));
                        QDate d(QDate::currentDate());
                        qDebug() << d.toString("d. MMM yyyy");;
                        return app.exec();
                    }
                    

                    QDate(Time)::toString() is using the system locale. If you want to use the default locale you have to use QLocale::toString()

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    2
                    • Fuel 0F Offline
                      Fuel 0F Offline
                      Fuel 0
                      wrote on last edited by
                      #10

                      Ah ok, didnt know that. I fixed my Model and now it works. Have to use something like this.

                      QLocale locale;
                      if (index.column() == 0)
                           return locale.toString(mItems.at(index.row())->date, "d. MMM yyyy");
                      
                      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