Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. cannot convert ‘const QString’ to ‘const QLocale&’
Forum Update on Monday, May 27th 2025

cannot convert ‘const QString’ to ‘const QLocale&’

Scheduled Pinned Locked Moved Solved Qt 6
qt6
20 Posts 6 Posters 1.8k Views
  • 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.
  • X Offline
    X Offline
    xavierbaez
    wrote on last edited by
    #1

    Hello. This error is affecting building an application and it’s affecting other files in the stacktrace. Have anybody experienced a similar problem? Hopefully with QStringnand QLocale&

    I’m upgrading an application from Qt5 to Qt6.

    Thanks

    Christian EhrlicherC 1 Reply Last reply
    0
    • X xavierbaez

      Hello. This error is affecting building an application and it’s affecting other files in the stacktrace. Have anybody experienced a similar problem? Hopefully with QStringnand QLocale&

      I’m upgrading an application from Qt5 to Qt6.

      Thanks

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @xavierbaez Please re-read your question and ask yourself how we should help here.

      Provide some code where you've problems with.

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

      X 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        @xavierbaez Please re-read your question and ask yourself how we should help here.

        Provide some code where you've problems with.

        X Offline
        X Offline
        xavierbaez
        wrote on last edited by
        #3

        @Christian-Ehrlicher I think I asked the question correctly

        jsulmJ Chris KawaC 2 Replies Last reply
        0
        • X xavierbaez

          @Christian-Ehrlicher I think I asked the question correctly

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @xavierbaez Really?!
          You do not even show the code which is causing this error - how should anybody help you?!

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • X xavierbaez

            @Christian-Ehrlicher I think I asked the question correctly

            Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by Chris Kawa
            #5

            @xavierbaez The error message says exactly what's wrong - you're passing a QString to where a QLocale is expected. Yes, a lot of people experience this problem with different types. The fix is always the same. Provide an argument of type that is expected.
            As Christian said - we can't tell you anything else without you showing the code that exhibits this error.

            X 1 Reply Last reply
            0
            • Chris KawaC Chris Kawa

              @xavierbaez The error message says exactly what's wrong - you're passing a QString to where a QLocale is expected. Yes, a lot of people experience this problem with different types. The fix is always the same. Provide an argument of type that is expected.
              As Christian said - we can't tell you anything else without you showing the code that exhibits this error.

              X Offline
              X Offline
              xavierbaez
              wrote on last edited by
              #6

              @Chris-Kawa okay thanks maybe I forgot to mention this worked and compiled and built fine with Qt5, so I guess the question 🙋🏻‍♂️ is more with “why would it work on Qt5 and not in Qt6”

              Christian EhrlicherC JonBJ jsulmJ 3 Replies Last reply
              0
              • X xavierbaez

                @Chris-Kawa okay thanks maybe I forgot to mention this worked and compiled and built fine with Qt5, so I guess the question 🙋🏻‍♂️ is more with “why would it work on Qt5 and not in Qt6”

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @xavierbaez Again: provide some code where it happens!

                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
                • X xavierbaez

                  @Chris-Kawa okay thanks maybe I forgot to mention this worked and compiled and built fine with Qt5, so I guess the question 🙋🏻‍♂️ is more with “why would it work on Qt5 and not in Qt6”

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @xavierbaez said in cannot convert ‘const QString’ to ‘const QLocale&’:

                  “why would it work on Qt5 and not in Qt6”

                  Maybe because a function which took a QString in Qt5 was changed to require a QLocale& in Qt6?

                  1 Reply Last reply
                  0
                  • X xavierbaez

                    @Chris-Kawa okay thanks maybe I forgot to mention this worked and compiled and built fine with Qt5, so I guess the question 🙋🏻‍♂️ is more with “why would it work on Qt5 and not in Qt6”

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @xavierbaez said in cannot convert ‘const QString’ to ‘const QLocale&’:

                    why would it work on Qt5 and not in Qt6

                    Because there were changes between Qt5 and Qt6, but as long as you refuse to show the code causing this error we can only guess...

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    X 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @xavierbaez said in cannot convert ‘const QString’ to ‘const QLocale&’:

                      why would it work on Qt5 and not in Qt6

                      Because there were changes between Qt5 and Qt6, but as long as you refuse to show the code causing this error we can only guess...

                      X Offline
                      X Offline
                      xavierbaez
                      wrote on last edited by
                      #10

                      @jsulm here’s the code

                      
                      bool BasicLogger::match(QString logFileName) const
                      
                      
                      jsulmJ JonBJ 2 Replies Last reply
                      0
                      • X xavierbaez

                        @jsulm here’s the code

                        
                        bool BasicLogger::match(QString logFileName) const
                        
                        
                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @xavierbaez said in cannot convert ‘const QString’ to ‘const QLocale&’:

                        here’s the code

                        No, this is not the code causing that error...

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • X xavierbaez

                          @jsulm here’s the code

                          
                          bool BasicLogger::match(QString logFileName) const
                          
                          
                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by JonB
                          #12

                          @xavierbaez
                          Nobody can answer from this without knowing what class BasicLogger is, since it's not a supplied Qt class, and hence the definition of match() if you are overriding it (or perhaps some other context)? You are amazingly "economical" with what you show in order to answer your question, I cannot understand why. In itself there is nothing you show which would error requiring QLocale instead of the QString you specify.

                          X 1 Reply Last reply
                          0
                          • JonBJ JonB

                            @xavierbaez
                            Nobody can answer from this without knowing what class BasicLogger is, since it's not a supplied Qt class, and hence the definition of match() if you are overriding it (or perhaps some other context)? You are amazingly "economical" with what you show in order to answer your question, I cannot understand why. In itself there is nothing you show which would error requiring QLocale instead of the QString you specify.

                            X Offline
                            X Offline
                            xavierbaez
                            wrote on last edited by xavierbaez
                            #13

                            @JonB

                            bool BasicLogger::match(QString logFileName) const
                            {
                                QRegExp re(QString(matchPattern).arg(_params.fileName));
                                return re.exactMatch(logFileName);
                            }
                            
                            Christian EhrlicherC JonBJ 2 Replies Last reply
                            0
                            • X xavierbaez

                              @JonB

                              bool BasicLogger::match(QString logFileName) const
                              {
                                  QRegExp re(QString(matchPattern).arg(_params.fileName));
                                  return re.exactMatch(logFileName);
                              }
                              
                              Christian EhrlicherC Offline
                              Christian EhrlicherC Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @xavierbaez said in cannot convert ‘const QString’ to ‘const QLocale&’:

                              QRegExp

                              This was deprecated in Qt5 and removed in Qt6 so I would be surprised if this compiles at all.

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

                              X 1 Reply Last reply
                              0
                              • Christian EhrlicherC Christian Ehrlicher

                                @xavierbaez said in cannot convert ‘const QString’ to ‘const QLocale&’:

                                QRegExp

                                This was deprecated in Qt5 and removed in Qt6 so I would be surprised if this compiles at all.

                                X Offline
                                X Offline
                                xavierbaez
                                wrote on last edited by
                                #15

                                @Christian-Ehrlicher said in cannot convert ‘const QString’ to ‘const QLocale&’:

                                @xavierbaez said in cannot convert ‘const QString’ to ‘const QLocale&’:

                                QRegExp

                                This was deprecated in Qt5 and removed in Qt6 so I would be surprised if this compiles at all.

                                Would you be so kind to let me know how would you write this?

                                1 Reply Last reply
                                0
                                • X xavierbaez

                                  @JonB

                                  bool BasicLogger::match(QString logFileName) const
                                  {
                                      QRegExp re(QString(matchPattern).arg(_params.fileName));
                                      return re.exactMatch(logFileName);
                                  }
                                  
                                  JonBJ Offline
                                  JonBJ Offline
                                  JonB
                                  wrote on last edited by JonB
                                  #16

                                  @xavierbaez said in cannot convert ‘const QString’ to ‘const QLocale&’:

                                  QRegExp re(QString(matchPattern).arg(_params.fileName));
                                  return re.exactMatch(logFileName);
                                  

                                  Try (untested)

                                  QRegularExpression re(QRegularExpression::anchoredPattern(QString(matchPattern).arg(_params.fileName)));
                                  return re.match(logFileName).hasMatch();
                                  

                                  You will need to change #include <QRegExp> to #include <QRegularExpression>.

                                  X 1 Reply Last reply
                                  1
                                  • V Offline
                                    V Offline
                                    Volker75
                                    wrote on last edited by Volker75
                                    #17

                                    Hallo,

                                    i got the same problem converting from Qt 5 to Qt 6. I understand the problem, but i don't know how to fix it.
                                    In my source it is this:

                                    app.installTranslator(&TTranslator);                    //this is fine
                                    QLocale::setDefault(TSettings->language);     //this is wrong
                                    

                                    While TSettings->language is a QString reading from QSettings.

                                    Chris KawaC 1 Reply Last reply
                                    0
                                    • V Volker75

                                      Hallo,

                                      i got the same problem converting from Qt 5 to Qt 6. I understand the problem, but i don't know how to fix it.
                                      In my source it is this:

                                      app.installTranslator(&TTranslator);                    //this is fine
                                      QLocale::setDefault(TSettings->language);     //this is wrong
                                      

                                      While TSettings->language is a QString reading from QSettings.

                                      Chris KawaC Offline
                                      Chris KawaC Offline
                                      Chris Kawa
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #18

                                      @Volker75 QLocale(const QString&) constructor was marked explicit in Qt6, so you have to, well, be explicit when you use that constructor :)

                                      QLocale::setDefault(QLocale(TSettings->language));
                                      
                                      V 1 Reply Last reply
                                      3
                                      • Chris KawaC Chris Kawa

                                        @Volker75 QLocale(const QString&) constructor was marked explicit in Qt6, so you have to, well, be explicit when you use that constructor :)

                                        QLocale::setDefault(QLocale(TSettings->language));
                                        
                                        V Offline
                                        V Offline
                                        Volker75
                                        wrote on last edited by
                                        #19

                                        @Chris-Kawa said in cannot convert ‘const QString’ to ‘const QLocale&’:

                                        QLocale(

                                        ah... so easy.. Thank you very much! I just tried and it can compile now that file. (Not the whole project yet, there are more errors, but i hope i can fix them myself)

                                        1 Reply Last reply
                                        0
                                        • JonBJ JonB

                                          @xavierbaez said in cannot convert ‘const QString’ to ‘const QLocale&’:

                                          QRegExp re(QString(matchPattern).arg(_params.fileName));
                                          return re.exactMatch(logFileName);
                                          

                                          Try (untested)

                                          QRegularExpression re(QRegularExpression::anchoredPattern(QString(matchPattern).arg(_params.fileName)));
                                          return re.match(logFileName).hasMatch();
                                          

                                          You will need to change #include <QRegExp> to #include <QRegularExpression>.

                                          X Offline
                                          X Offline
                                          xavierbaez
                                          wrote on last edited by
                                          #20

                                          @JonB said in cannot convert ‘const QString’ to ‘const QLocale&’:

                                          @xavierbaez said in cannot convert ‘const QString’ to ‘const QLocale&’:

                                          QRegExp re(QString(matchPattern).arg(_params.fileName));
                                          return re.exactMatch(logFileName);
                                          

                                          Try (untested)

                                          QRegularExpression re(QRegularExpression::anchoredPattern(QString(matchPattern).arg(_params.fileName)));
                                          return re.match(logFileName).hasMatch();
                                          

                                          You will need to change #include <QRegExp> to #include <QRegularExpression>.

                                          Yeah that worked thank you so much.

                                          1 Reply Last reply
                                          0
                                          • X xavierbaez has marked this topic as solved on

                                          • Login

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