Results 1 to 8 of 8

Thread: SQLQUERY - column value retrun problem

  1. #1
    Join Date
    Feb 2010
    Posts
    23
    Qt products
    Qt3 Qt4
    Platforms
    Windows Symbian S60

    Question SQLQUERY - column value retrun problem

    Dear All

    here is my code
    The i value always retruning "0"
    but the column value contains "1" also.

    what mistake in the below code? why i return always zero?

    Qt Code:
    1. void Edit::OpenEditor(QListWidgetItem* item1)
    2. {
    3. int rowno = activeRow();
    4. RowItems = iDBConnect->Selecting();
    5.  
    6. if(selectedRow == previousRow)
    7. {
    8. QString string1 = item1->text();
    9. iFilterUpdate = new FilterUpdate();
    10. iFilterUpdate->ui.lineEdit->setText(string1);
    11. FilterNumb* item = RowItems[rowno];
    12. iFilterUpdate->activeRow(item->id);
    13. TInt i;
    14. QSqlQuery query;
    15. query.exec(QString("select Enable from FilterNumTable where id = %1")
    16. .arg(item->id));
    17. if (query.next())
    18. {
    19. i = query.value(2).toBool();
    20. }
    21. if(i)
    22. {
    23. iFilterUpdate->ui.CheckEnable->setCheckState(Qt::Checked);
    24. }
    25. else
    26. {
    27. iFilterUpdate->ui.CheckDisable->setCheckState(Qt::Checked);
    28. }
    29.  
    30. this->close();
    31. }
    32. else
    33. {
    34. previousRow = selectedRow;
    35. }
    36. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: SQLQUERY - column value retrun problem

    toBool() returns a bool.
    Use toInt()

  3. #3
    Join Date
    Feb 2010
    Posts
    23
    Qt products
    Qt3 Qt4
    Platforms
    Windows Symbian S60

    Question Re: SQLQUERY - column value retrun problem

    Quote Originally Posted by tbscope View Post
    toBool() returns a bool.
    Use toInt()
    Dear tbscope,

    thx for ur answer, i used toInt() also but same problem comming.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: SQLQUERY - column value retrun problem

    Add these lines:

    At the top of your code
    Qt Code:
    1. #include <QDebug>
    To copy to clipboard, switch view to plain text mode 

    Just above i = query.value(2).toBool();
    Qt Code:
    1. qDebug() << "query value =" << query.value(2);
    To copy to clipboard, switch view to plain text mode 

    Then run it and look what the actual value is.

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: SQLQUERY - column value retrun problem

    Regardless if i is 0 or 1 you always set the state Qt::Checked! Use Qt::Unchecked for the else scope.

  6. #6
    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: SQLQUERY - column value retrun problem

    Quote Originally Posted by Lykurg View Post
    Regardless if i is 0 or 1 you always set the state Qt::Checked! Use Qt::Unchecked for the else scope.
    The Qt::Checked state is being set on two different controls. If they are in a QButtonGroup then they might be automatically exclusive. This would usually be done with QRadioButton or a single QCheckBox though.

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: SQLQUERY - column value retrun problem

    Quote Originally Posted by ChrisW67 View Post
    The Qt::Checked state is being set on two different controls.
    Ups, you are right, my eyes aren't absolutely open yet...

  8. #8
    Join Date
    Feb 2010
    Posts
    23
    Qt products
    Qt3 Qt4
    Platforms
    Windows Symbian S60

    Thumbs up Re: SQLQUERY - column value retrun problem

    Dear All,

    issue is resolved , thx for all .

Similar Threads

  1. Casting in a select sqlQuery
    By Kesy in forum Qt Programming
    Replies: 3
    Last Post: 25th November 2008, 15:12
  2. Sum of a column in QSqlTableModel
    By giusepped in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2008, 23:38
  3. Table Column Problem
    By kenny_isles in forum Newbie
    Replies: 1
    Last Post: 5th March 2007, 23:35
  4. Column with numbers
    By ederbs in forum Qt Programming
    Replies: 1
    Last Post: 29th November 2006, 22:03
  5. Column Sorting
    By sumsin in forum Qt Programming
    Replies: 1
    Last Post: 16th June 2006, 07:48

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.