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 Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved Qt 6
qt6
20 Posts 6 Posters 2.6k Views 3 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.
  • X xavierbaez
    31 Mar 2023, 07:01

    @Christian-Ehrlicher I think I asked the question correctly

    J Offline
    J Offline
    jsulm
    Lifetime Qt Champion
    wrote on 31 Mar 2023, 07:03 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
      31 Mar 2023, 07:01

      @Christian-Ehrlicher I think I asked the question correctly

      C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 31 Mar 2023, 07:04 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 31 Mar 2023, 07:21
      0
      • C Chris Kawa
        31 Mar 2023, 07:04

        @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 31 Mar 2023, 07:21 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”

        C J J 3 Replies Last reply 31 Mar 2023, 07:21
        0
        • X xavierbaez
          31 Mar 2023, 07:21

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

          C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 31 Mar 2023, 07:21 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
            31 Mar 2023, 07:21

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

            J Offline
            J Offline
            JonB
            wrote on 31 Mar 2023, 07:38 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
              31 Mar 2023, 07:21

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

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 31 Mar 2023, 07:39 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 31 Mar 2023, 08:47
              0
              • J jsulm
                31 Mar 2023, 07:39

                @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 31 Mar 2023, 08:47 last edited by
                #10

                @jsulm here’s the code

                
                bool BasicLogger::match(QString logFileName) const
                
                
                J J 2 Replies Last reply 31 Mar 2023, 08:49
                0
                • X xavierbaez
                  31 Mar 2023, 08:47

                  @jsulm here’s the code

                  
                  bool BasicLogger::match(QString logFileName) const
                  
                  
                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 31 Mar 2023, 08:49 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
                    31 Mar 2023, 08:47

                    @jsulm here’s the code

                    
                    bool BasicLogger::match(QString logFileName) const
                    
                    
                    J Offline
                    J Offline
                    JonB
                    wrote on 31 Mar 2023, 08:50 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 31 Mar 2023, 15:55
                    0
                    • J JonB
                      31 Mar 2023, 08:50

                      @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 31 Mar 2023, 15:55 last edited by xavierbaez
                      #13

                      @JonB

                      bool BasicLogger::match(QString logFileName) const
                      {
                          QRegExp re(QString(matchPattern).arg(_params.fileName));
                          return re.exactMatch(logFileName);
                      }
                      
                      C J 2 Replies Last reply 31 Mar 2023, 16:31
                      0
                      • X xavierbaez
                        31 Mar 2023, 15:55

                        @JonB

                        bool BasicLogger::match(QString logFileName) const
                        {
                            QRegExp re(QString(matchPattern).arg(_params.fileName));
                            return re.exactMatch(logFileName);
                        }
                        
                        C Offline
                        C Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on 31 Mar 2023, 16:31 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 31 Mar 2023, 16:44
                        0
                        • C Christian Ehrlicher
                          31 Mar 2023, 16:31

                          @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 31 Mar 2023, 16:44 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
                            31 Mar 2023, 15:55

                            @JonB

                            bool BasicLogger::match(QString logFileName) const
                            {
                                QRegExp re(QString(matchPattern).arg(_params.fileName));
                                return re.exactMatch(logFileName);
                            }
                            
                            J Offline
                            J Offline
                            JonB
                            wrote on 31 Mar 2023, 17:43 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 6 Apr 2023, 05:12
                            1
                            • V Offline
                              V Offline
                              Volker75
                              wrote on 3 Apr 2023, 17:05 last edited by Volker75 4 Mar 2023, 17:12
                              #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.

                              C 1 Reply Last reply 3 Apr 2023, 17:15
                              0
                              • V Volker75
                                3 Apr 2023, 17:05

                                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.

                                C Offline
                                C Offline
                                Chris Kawa
                                Lifetime Qt Champion
                                wrote on 3 Apr 2023, 17:15 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 Apr 2023, 17:28
                                3
                                • C Chris Kawa
                                  3 Apr 2023, 17:15

                                  @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 3 Apr 2023, 17:28 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
                                  • J JonB
                                    31 Mar 2023, 17:43

                                    @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 6 Apr 2023, 05:12 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 6 Apr 2023, 05:30

                                    13/20

                                    31 Mar 2023, 15:55

                                    • Login

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