Results 1 to 5 of 5

Thread: Problem QT : Comparison from the base

  1. #1
    Join Date
    Jan 2012
    Posts
    25
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem QT : Comparison from the base

    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:
    Qt Code:
    1. QSqlQuery query11;
    2. query11.prepare("SELECT Seuil_Min FROM Projet.dbo.Produit WHERE Nom=:nom");
    3. query11.bindValue(":nom", ui->comboBox->currentText());
    4. if (query11.exec() && query11.next()) {
    5. ui->textBrowser->setText(query11.value(0).toString());
    6. qint8 min=query11.value(0).toInt();
    7.  
    8. QSqlQuery query12;
    9. query12.prepare("SELECT Quantité FROM Projet.dbo.Produit WHERE Nom=:nom");
    10. query12.bindValue(":nom", ui->comboBox->currentText());
    11. if (query12.exec() && query12.next()) {
    12. qint8 qt = query12.value(0).toInt();
    13. qDebug()<< qt;
    14. qDebug()<< min;
    15. }
    16.  
    17.  
    18. if(qt <= min){
    19. QMessageBox::warning(this,"Information","Vous avez atteint le seuil minimal de ce produit. Un message d'alerte sera envoyé au système centrale !");
    20. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2009
    Location
    The Netherlands and Spain
    Posts
    150
    Thanks
    6
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Problem QT : Comparison from the base

    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?)

  3. #3
    Join Date
    Jan 2012
    Posts
    25
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem QT : Comparison from the base

    thank u for answering me
    the data type : both are int
    min is which giving the unexpected result

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Problem QT : Comparison from the base

    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.

  5. #5
    Join Date
    Jan 2012
    Posts
    25
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem QT : Comparison from the base

    Thanks. I solved the problem

Similar Threads

  1. Replies: 4
    Last Post: 19th December 2010, 06:15
  2. problem in selecting base class
    By durgarao in forum Qt Tools
    Replies: 5
    Last Post: 2nd January 2009, 10:13
  3. pointer base problem
    By mickey in forum General Programming
    Replies: 2
    Last Post: 7th November 2007, 21:36
  4. QTable - Data Base Problem
    By esq in forum Qt Tools
    Replies: 9
    Last Post: 27th May 2007, 23:08
  5. QTable - Date Base Problem
    By esq in forum Qt Programming
    Replies: 4
    Last Post: 23rd May 2007, 02:32

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
  •  
Qt is a trademark of The Qt Company.