Qt-interest Archive, February 2008
convert qvariant to int
Message 1 in thread
My application compares the number of record between the tables of 2 DB.
I?ve wrote :
QSqlQuery srcQuery(dbDest);
QSqlQuery dstQuery(dbSrc);
QString strCmd = QString("select count(*) from %1").arg(tablename);
srcQuery.exec(strCmd);
dstQuery.exec(strCmd);
if(srcQuery.value(0).toInt() > dstQuery.value(0).toInt())
{
tabModified << QString("%1 %2").arg(tablename, QString("%1 enregistrements
supprimés").arg(srcQuery.value(0).toInt() - dstQuery.value(0).toInt()));
}
else if (srcQuery.value(0).toInt() < dstQuery.value(0).toInt())
{
tabModified << QString("%1 %2").arg(tablename, QString("%1 enregistrements
ajoutés").arg(dstQuery.value(0).toInt() - srcQuery.value(0).toInt()));
}
But always I?ve srcQuery.value(0).toInt() and dstQuery.value(0).toInt()
equal to 0. I think it?s a problem of converting QVariant to int.
Did anyone can help me.
thanks
Message 2 in thread
QVariant is not the problem in your case.
As far as i can see your didn't check that the result of your query is
valid. You also didn't verify that your pointing on a valid record in
the result.
Add something like this before doing your test:
code snippet:
/*
This will get you the first record from the result of the query
*/
if( !query.first() )
{
//Add better suitable management for your soft here
qDebug() << "Empty result";
return;
}
Cheers
Samuel
>>> "HEDFI Mourad" <mourad@xxxxxxxx> 02/27/08 10:54 >>>
My application compares the number of record between the tables of 2
DB.
Iâve wrote :
QSqlQuery srcQuery(dbDest);
QSqlQuery dstQuery(dbSrc);
QString strCmd = QString("select count(*) from
%1").arg(tablename);
srcQuery.exec(strCmd);
dstQuery.exec(strCmd);
if(srcQuery.value(0).toInt() > dstQuery.value(0).toInt())
{
tabModified << QString("%1 %2").arg(tablename, QString("%1
enregistrements
supprimÃs").arg(srcQuery.value(0).toInt() -
dstQuery.value(0).toInt()));
}
else if (srcQuery.value(0).toInt() < dstQuery.value(0).toInt())
{
tabModified << QString("%1 %2").arg(tablename, QString("%1
enregistrements
ajoutÃs").arg(dstQuery.value(0).toInt() - srcQuery.value(0).toInt()));
}
But always Iâve srcQuery.value(0).toInt() and
dstQuery.value(0).toInt()
equal to 0. I think itâs a problem of converting QVariant to int.
Did anyone can help me.
thanks
--
[ signature omitted ]
Message 3 in thread
Thank you for response. It's true that I'm not on the right record. But I've
just added .next() after queries execution and it works.
Thank you.
-----Message d'origine-----
De : Samuel Gaist [mailto:Samuel.Gaist@xxxxxxx]
Envoyé : mercredi 27 février 2008 11:25
À : qt-interest@xxxxxxxxxxxxx
Objet : Rép. : convert qvariant to int
QVariant is not the problem in your case.
As far as i can see your didn't check that the result of your query is
valid. You also didn't verify that your pointing on a valid record in
the result.
Add something like this before doing your test:
code snippet:
/*
This will get you the first record from the result of the query
*/
if( !query.first() )
{
//Add better suitable management for your soft here
qDebug() << "Empty result";
return;
}
Cheers
Samuel
>>> "HEDFI Mourad" <mourad@xxxxxxxx> 02/27/08 10:54 >>>
My application compares the number of record between the tables of 2
DB.
I?ve wrote :
QSqlQuery srcQuery(dbDest);
QSqlQuery dstQuery(dbSrc);
QString strCmd = QString("select count(*) from
%1").arg(tablename);
srcQuery.exec(strCmd);
dstQuery.exec(strCmd);
if(srcQuery.value(0).toInt() > dstQuery.value(0).toInt())
{
tabModified << QString("%1 %2").arg(tablename, QString("%1
enregistrements
supprimés").arg(srcQuery.value(0).toInt() -
dstQuery.value(0).toInt()));
}
else if (srcQuery.value(0).toInt() < dstQuery.value(0).toInt())
{
tabModified << QString("%1 %2").arg(tablename, QString("%1
enregistrements
ajoutés").arg(dstQuery.value(0).toInt() - srcQuery.value(0).toInt()));
}
But always I?ve srcQuery.value(0).toInt() and
dstQuery.value(0).toInt()
equal to 0. I think it?s a problem of converting QVariant to int.
Did anyone can help me.
thanks
--
[ signature omitted ]