Another Exception with locale: cannot convert ‘const QString’ to ‘const QLocale&’
-
I got another problem with Qlocale
Here is the code in the header file
Validating.h:void setLocale(const QString& locale);
Here is the code in the C++ file
Validating.cpp:void Validating::setLocale(const QString& locale) { QValidator::setLocale(locale); }
Here is the error
error: cannot convert ‘const QString’ to ‘const QLocale&’ | QValidator::setLocale(locale); | ^~~~~~
Thanks in advance
-
@xavierbaez said in Another Exception with locale: cannot convert ‘const QString’ to ‘const QLocale&’:
void Validating::setLocale(const QString& locale)
{
QValidator::setLocale(locale);
}what you probably want is:
void Validating::setLocale(const QString& locale) { QValidator::setLocale(QLocale(locale)); }
which will create a QLocale object from your QString and pass it on to QValidator.
-
@xavierbaez The error message is very clear and if you read documentation (https://doc.qt.io/qt-6/qvalidator.html#setLocale) you will see that setLocale expects a QLocale as parameter, not QString.
-
@jsulm said in Another Exception with locale: cannot convert ‘const QString’ to ‘const QLocale&’:
@xavierbaez The error message is very clear and if you read documentation (https://doc.qt.io/qt-6/qvalidator.html#setLocale) you will see that setLocale expects a QLocale as parameter, not QString.
I replaced it with this code:
Validating.hvoid setLocale(const QLocale &locale);
void Validating::setLocale(const QLocale &locale) { QValidator::setLocale(&locale); }
I get the following error:
initializing argument 1 of ‘void Validating::setLocale(const QLocale&)’ 15 | void setLocale(const QLocale &locale);
-
@xavierbaez said in Another Exception with locale: cannot convert ‘const QString’ to ‘const QLocale&’:
QValidator::setLocale(&locale);
Why are you trying to pass a pointer here?!
-
@xavierbaez said in Another Exception with locale: cannot convert ‘const QString’ to ‘const QLocale&’:
@jsulm said in Another Exception with locale: cannot convert ‘const QString’ to ‘const QLocale&’:
@xavierbaez The error message is very clear and if you read documentation (https://doc.qt.io/qt-6/qvalidator.html#setLocale) you will see that setLocale expects a QLocale as parameter, not QString.
I replaced it with this code:
Validating.hvoid setLocale(const QLocale &locale);
void Validating::setLocale(const QLocale &locale) { QValidator::setLocale(&locale); }
I get the following error:
initializing argument 1 of ‘void Validating::setLocale(const QLocale&)’ 15 | void setLocale(const QLocale &locale);
Would you be so kind to write the suggested code?
I tried everythning15 | void setLocale(const QLocale& locale);
If you change it
15 | void setLocale(const QLocale locale);
-
@xavierbaez You did not answer my question: "Why are you trying to pass a pointer here?!"
So, simply replaceQValidator::setLocale(&locale);
with
QValidator::setLocale(locale);
-
@xavierbaez said in Another Exception with locale: cannot convert ‘const QString’ to ‘const QLocale&’:
void Validating::setLocale(const QString& locale)
{
QValidator::setLocale(locale);
}what you probably want is:
void Validating::setLocale(const QString& locale) { QValidator::setLocale(QLocale(locale)); }
which will create a QLocale object from your QString and pass it on to QValidator.
-