cannot convert ‘const QString’ to ‘const QLocale&’
-
wrote on 31 Mar 2023, 06:37 last edited by
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
-
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
@xavierbaez Please re-read your question and ask yourself how we should help here.
Provide some code where you've problems with.
-
@xavierbaez Please re-read your question and ask yourself how we should help here.
Provide some code where you've problems with.
wrote on 31 Mar 2023, 07:01 last edited by@Christian-Ehrlicher I think I asked the question correctly
-
@Christian-Ehrlicher I think I asked the question correctly
@xavierbaez Really?!
You do not even show the code which is causing this error - how should anybody help you?! -
@Christian-Ehrlicher I think I asked the question correctly
@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. -
@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.wrote on 31 Mar 2023, 07:21 last edited by@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”
-
@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”
@xavierbaez Again: provide some code where it happens!
-
@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”
wrote on 31 Mar 2023, 07:38 last edited by@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 aQLocale&
in Qt6? -
@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”
@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...
-
@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...
wrote on 31 Mar 2023, 08:47 last edited by@jsulm here’s the code
bool BasicLogger::match(QString logFileName) const
-
@jsulm here’s the code
bool BasicLogger::match(QString logFileName) const
@xavierbaez said in cannot convert ‘const QString’ to ‘const QLocale&’:
here’s the code
No, this is not the code causing that error...
-
@jsulm here’s the code
bool BasicLogger::match(QString logFileName) const
wrote on 31 Mar 2023, 08:50 last edited by JonB@xavierbaez
Nobody can answer from this without knowing what classBasicLogger
is, since it's not a supplied Qt class, and hence the definition ofmatch()
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 requiringQLocale
instead of theQString
you specify. -
@xavierbaez
Nobody can answer from this without knowing what classBasicLogger
is, since it's not a supplied Qt class, and hence the definition ofmatch()
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 requiringQLocale
instead of theQString
you specify.wrote on 31 Mar 2023, 15:55 last edited by xavierbaezbool BasicLogger::match(QString logFileName) const { QRegExp re(QString(matchPattern).arg(_params.fileName)); return re.exactMatch(logFileName); }
-
bool BasicLogger::match(QString logFileName) const { QRegExp re(QString(matchPattern).arg(_params.fileName)); return re.exactMatch(logFileName); }
@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.
-
@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.
wrote on 31 Mar 2023, 16:44 last edited by@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?
-
bool BasicLogger::match(QString logFileName) const { QRegExp re(QString(matchPattern).arg(_params.fileName)); return re.exactMatch(logFileName); }
wrote on 31 Mar 2023, 17:43 last edited by 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>
. -
wrote on 3 Apr 2023, 17:05 last edited by Volker75 4 Mar 2023, 17:12
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.
-
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.
@Volker75
QLocale(const QString&)
constructor was markedexplicit
in Qt6, so you have to, well, be explicit when you use that constructor :)QLocale::setDefault(QLocale(TSettings->language));
-
@Volker75
QLocale(const QString&)
constructor was markedexplicit
in Qt6, so you have to, well, be explicit when you use that constructor :)QLocale::setDefault(QLocale(TSettings->language));
wrote on 3 Apr 2023, 17:28 last edited by@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)
-
@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>
.wrote on 6 Apr 2023, 05:12 last edited by@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/20