QSqlRecord...retrieving informations
I have a QSqlQuery as follows:
Code:
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:
Code:
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:
Re: QSqlRecord...retrieving informations
maybe try to convert the int to String with
Code:
Qstring dispString
= QString::number(disp,
10);
qDebug()<<"available: "<<dispString ;
Re: QSqlRecord...retrieving informations
What happens if you use toDouble() instead of toInt()? What is the type of availableNol?
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!