Results 1 to 3 of 3

Thread: query float values from mysql. But the type is QVariant::String

  1. #1
    Join Date
    Sep 2009
    Posts
    4

    Unhappy query float values from mysql. But the type is QVariant::String

    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.

    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.
    Last edited by zhnde; 18th November 2009 at 20:12.

  2. #2
    Join Date
    Jul 2009
    Location
    Italy, Pieve Ligure (GE)
    Posts
    55
    Thanks
    7
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: query float values from mysql. But the type is QVariant::String

    Have you tried QVariant::toDouble()? Something like:
    Qt Code:
    1. myDouble = query.value(<column_number>).toDouble();
    To copy to clipboard, switch view to plain text mode 
    where query is your QSqlQuery object.
    M.

  3. #3
    Join Date
    Sep 2009
    Posts
    4

    Default Re: query float values from mysql. But the type is QVariant::String

    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.

Similar Threads

  1. Compile 4.4.0
    By LordQt in forum Installation and Deployment
    Replies: 18
    Last Post: 29th May 2008, 13:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.