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.1k 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

    @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