PDA

View Full Version : Problem QT : Comparison from the base



anouar2002
22nd February 2012, 20:58
Hi everyone,
I'm working on a Qt application that interacts with a SQL database Server.Je want tocompare two fields retrieved from the database.
But there will always be an error in the comparison.
When I view the fields in the console.
The first is displayed correctly. (An integer)
But the second is displayed as a hex shape I think. Example: if the retrieved value is'1 ', the value is '0 x6a112f16'.
Here is a portion of the code:


QSqlQuery query11;
query11.prepare("SELECT Seuil_Min FROM Projet.dbo.Produit WHERE Nom=:nom");
query11.bindValue(":nom", ui->comboBox->currentText());
if (query11.exec() && query11.next()) {
ui->textBrowser->setText(query11.value(0).toString());
qint8 min=query11.value(0).toInt();

QSqlQuery query12;
query12.prepare("SELECT Quantité FROM Projet.dbo.Produit WHERE Nom=:nom");
query12.bindValue(":nom", ui->comboBox->currentText());
if (query12.exec() && query12.next()) {
qint8 qt = query12.value(0).toInt();
qDebug()<< qt;
qDebug()<< min;
}


if(qt <= min){
QMessageBox::warning(this,"Information","Vous avez atteint le seuil minimal de ce produit. Un message d'alerte sera envoyé au système centrale !");
}

boudie
22nd February 2012, 21:36
Maybe there is some uninitialized data in the database?
What data type are the fields Seuil_Min and Quantité?
Which value is giving the unexpected result? The first one read or the first one written (qt or min?)

anouar2002
22nd February 2012, 21:50
thank u for answering me
the data type : both are int
min is which giving the unexpected result

ChrisW67
22nd February 2012, 23:17
If your code is exactly as posted then min is declared qint8 at line 6 and is still in scope at line 14 (the if() at line 4 is not closed). An 8 bit integer cannot possibly give 0x6a112f16 as its value: it only has one byte. BTW: The value could overflow if the database contains numbers greater than 127 or less the -128 in the subject columns.

If your code is not exactly as posted, and if() at line 4 is closed before line 14, then min is some other variable from a broader scope.

anouar2002
22nd February 2012, 23:20
Thanks. I solved the problem