[Qt-interest] SQL (ODBC) retreiving doubles incorrectly

Andre Somers andre at familiesomers.nl
Fri Oct 2 14:27:09 CEST 2009


Julien Cugnière wrote:
> 2009/10/2 Andre Somers <andre at familiesomers.nl>
>   
>> use qDebug() << on the variant value returned from the query, I get
>> QVariant(QString, "E-3") as the result. Retreiving the type of the field
>> using QSqlRecord::field() and QSqlField::type() returns QVariant::double
>> though.
>>     
>
> You can try using query.setNumericalPrecisionPolicy(QSql::LowPrecisionDouble).
>
> If you don't, Qt often returns number as strings in order to preserve
> the precision of the database, which can be greater than that of a
> double. AFAIK, the exact format of the string is database-dependant,
> and there's no guarantee it can be parsed by QString::toDouble.
>
>
>   
Thanks for the tip, I had not looked into this option before. 
Unfortunately, it makes things worse. Instead of an QVariant(QString, 
"E-3") on my debug, I now get an QVariant(, ). That probably means an 
empty or invalid value. Not a real improvement over the string...

I have hacked around the issue for now by multiplying the value I am 
after in my query, and deviding it by the same value again after 
retreiving it. Still, this is an extremely ugly hack, and I'd like to 
get rid of it...

André





More information about the Qt-interest-old mailing list