Results 1 to 4 of 4

Thread: QSqlRecord...retrieving informations

  1. #1
    Join Date
    Jun 2008
    Location
    Italy
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QSqlRecord...retrieving informations

    I have a QSqlQuery as follows:
    Qt Code:
    1. QSqlQuery q("SELECT video.codVideo, video.codSupporto, video.title, SUM(availableNol) AS available
    2. FROM video INNER JOIN dvd ON (video.codSupporto=dvd.codSupporto) AND (video.codVideo=dvd.codVideo)
    3. GROUP BY video.codVideo, video.codSupporto, title");
    To copy to clipboard, switch view to plain text mode 

    Then I created a queryModel and a QSqlRecord called record..everything OK the table is correctly printed and I can retrieve almost all fields except the one called available which is a calculated one..I tried:
    Qt Code:
    1. int disp = record.value(3).toInt();
    2. qDebug()<<"available: "<<disp;
    To copy to clipboard, switch view to plain text mode 
    but qDebug always returns 0 even if it is correctly printed in the table view.
    Is it a problem retrieving calculated values in a query?

  2. #2
    Join Date
    Jul 2008
    Posts
    69
    Thanks
    9
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlRecord...retrieving informations

    maybe try to convert the int to String with
    Qt Code:
    1. Qstring dispString = QString::number(disp,10);
    2. qDebug()<<"available: "<<dispString ;
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlRecord...retrieving informations

    What happens if you use toDouble() instead of toInt()? What is the type of availableNol?

  4. #4
    Join Date
    Aug 2006
    Location
    Germany
    Posts
    15
    Thanks
    1
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QSqlRecord...retrieving informations

    even the last post is some time ago..

    i noticed the same behavior since qt 4.4.3 (and still with 4.5.0 is the same).
    my project formerly worked correct. after i compiled with 4.4.3 i got the same problems.

    i just found out, that all data fom the sql server which have type "floating point" will be recognized as QString (e.g. "9000.5"). This cannot be converted into integer, but into float or double.
    QSqlQuery().data() will return QVariant. QVariant().type() returnes "Qstring". When i cast the values into integer inside my sql-query everythings is correct.
    But i cant use integer everywhere..

    Doeas the new Qt-versions handle those datatypes different than before? Or is this just a bug? ..or my mistake?

    Sorry for my bad english!

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.