cannot convert ‘const QString’ to ‘const QLocale&’
-
@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. -
@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!
-
@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? -
@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&’:
here’s the code
No, this is not the code causing that error...
-
@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 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.
-
@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?
-
@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>
. -
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));
-
@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)
-
@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.
-