Check if conversion was successful before passing to locale

This commit is contained in:
Alessandro Pasotti 2018-06-09 18:42:14 +02:00
parent 85e34f2c92
commit bf810e9c50

View File

@ -244,11 +244,14 @@ QString QgsField::displayString( const QVariant &v ) const
return QString::number( v.toDouble(), 'f', d->precision ); return QString::number( v.toDouble(), 'f', d->precision );
} }
} }
// Other numeric types out of doubles // Other numeric types than doubles
else if ( isNumeric() && else if ( isNumeric() &&
! QLocale().numberOptions() & QLocale::NumberOption::OmitGroupSeparator ) ! QLocale().numberOptions() & QLocale::NumberOption::OmitGroupSeparator )
{ {
return QLocale().toString( v.toLongLong() ); bool ok;
qlonglong converted( v.toLongLong( &ok ) );
if ( ok )
return QLocale().toString( converted );
} }
// Fallback if special rules do not apply // Fallback if special rules do not apply
return v.toString(); return v.toString();
@ -305,7 +308,7 @@ bool QgsField::convertCompatible( QVariant &v ) const
QVariant tmp( v ); QVariant tmp( v );
if ( d->type == QVariant::Double && !tmp.convert( d->type ) ) if ( d->type == QVariant::Double && !tmp.convert( d->type ) )
{ {
v = v.toString().replace( ',', '.' ); v = v.toString().replace( QLocale().decimalPoint(), '.' );
} }
} }