PDA

View Full Version : SQLQUERY - column value retrun problem



damodharan
27th May 2010, 05:06
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?



void Edit::OpenEditor(QListWidgetItem* item1)
{
int rowno = activeRow();
RowItems = iDBConnect->Selecting();

if(selectedRow == previousRow)
{
QString string1 = item1->text();
iFilterUpdate = new FilterUpdate();
iFilterUpdate->ui.lineEdit->setText(string1);
FilterNumb* item = RowItems[rowno];
iFilterUpdate->activeRow(item->id);
TInt i;
QSqlQuery query;
query.exec(QString("select Enable from FilterNumTable where id = %1")
.arg(item->id));
if (query.next())
{
i = query.value(2).toBool();
}
if(i)
{
iFilterUpdate->ui.CheckEnable->setCheckState(Qt::Checked);
}
else
{
iFilterUpdate->ui.CheckDisable->setCheckState(Qt::Checked);
}

this->close();
}
else
{
previousRow = selectedRow;
}
}

tbscope
27th May 2010, 05:51
toBool() returns a bool.
Use toInt()

damodharan
27th May 2010, 05:58
toBool() returns a bool.
Use toInt()

Dear tbscope,

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

tbscope
27th May 2010, 06:04
Add these lines:

At the top of your code

#include <QDebug>

Just above i = query.value(2).toBool();

qDebug() << "query value =" << query.value(2);

Then run it and look what the actual value is.

Lykurg
27th May 2010, 06:09
Regardless if i is 0 or 1 you always set the state Qt::Checked! Use Qt::Unchecked for the else scope.

ChrisW67
27th May 2010, 06:40
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.

Lykurg
27th May 2010, 07:01
The Qt::Checked state is being set on two different controls.Ups, you are right, my eyes aren't absolutely open yet...

damodharan
27th May 2010, 07:09
Dear All,

issue is resolved , thx for all .