PDA

View Full Version : query float values from mysql. But the type is QVariant::String



zhnde
18th November 2009, 20:08
Hello All,

i have a Problem by getting float numbers via QSqlDatabase from mysql under windows. The queried results are saved in QVariant. But they have the type of QVariant::String, where QVariant::Double was expected.:(

The QVariant::Type is used for translating e.g. a float number in german is like 2,50, which in English is 2.50.

I'v tested with winxp, win7, mysql 5.4, Qt4.3.4, Qt4.5.3.
The Program works fine under linux.:rolleyes:

It must be a problem of QT-Win, because I'v tried to connect the Mysql-Servers running on windows and linux.

does anybody have the same problem? Or who knows why it happened.:confused:

miwarre
19th November 2009, 10:57
Have you tried QVariant::toDouble() ? Something like:

myDouble = query.value(<column_number>).toDouble();
where query is your QSqlQuery object.
M.

zhnde
10th December 2009, 20:51
Thanks for the reply.

Yes, I'v tried and it works. I'v liked some code that do not depend on the contents of the Database. The Qt-linux can tell the type correctly from the queried table, while Qt-Windows fails. If someone else has the same problem, it must be a bug. I have not tried the 4.6. Hope it is gone.