#include #include #include #include static void check( const QValidator& qv, const QString& input, const bool shouldBeValid) { int p( 0); QString s( input); const bool isValid( qv.validate( s, p) == QValidator::Acceptable); qDebug() << s << (isValid ? "is valid" : "is not valid"); QString msg; if( isValid != shouldBeValid) { qDebug() << "PROBLEM"; } qDebug() << "expected behaviour (" << (isValid ? "" : "not") << "valid value)" << endl; } int main(int argc, char *argv[]) { QApplication a(argc, argv); // first try: German locale QLocale german(QLocale::German, QLocale::Germany); QLocale::setDefault(german); QDoubleValidator germanV( 2.0, 2222.0, 5, 0); check( germanV, "1.000", false); check( germanV, "1,000", false); // second try: English locale QLocale::setDefault(QLocale::c()); QDoubleValidator englishV( 2.0, 2222.0, 5, 0); check( englishV, "1.000", false); check( englishV, "1,000", false); return 0; }