PDA

View Full Version : QSqlRecord...retrieving informations



lord_shadow
17th October 2008, 12:02
I have a QSqlQuery as follows:


QSqlQuery q("SELECT video.codVideo, video.codSupporto, video.title, SUM(availableNol) AS available
FROM video INNER JOIN dvd ON (video.codSupporto=dvd.codSupporto) AND (video.codVideo=dvd.codVideo)
GROUP BY video.codVideo, video.codSupporto, title");


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:


int disp = record.value(3).toInt();
qDebug()<<"available: "<<disp;

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? :confused: :confused:

SunnySan
17th October 2008, 13:27
maybe try to convert the int to String with



Qstring dispString = QString::number(disp,10);
qDebug()<<"available: "<<dispString ;

jacek
23rd October 2008, 01:34
What happens if you use toDouble() instead of toInt()? What is the type of availableNol?

pinktroll
5th March 2009, 12:54
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!