PDA

View Full Version : QListwidget with checkbox compare sql table



damodharan
28th May 2010, 17:47
Dear all,

Any one have idea about how to compare the listwidet data with Database table with each row?

damodharan
28th May 2010, 18:04
Dear All

Here is my snippet code
can any one help me how to change the value in the DB table once we
change the check box in list widget

i have some list of data in listwidget.
ii chance second check box enable & three checkbox Disable

after i am calling this below function ?



void FC::Config()
{
messageBox = new QMessageBox(this);
if (QMessageBox::Ok == messageBox->question(this, "QDelete", "Config update?",
QMessageBox::Ok | QMessageBox::Cancel))
{
TInt NCounts = ui.listWidget->count();
TBuf<100> CCounts;
CCounts.AppendNum(NCounts);
int i;
int j =1;


for(i=0; i<NCounts; i++)
{

if(ui.listWidget->item(i)->checkState() == Qt::Checked)
{
bool ret;
QSqlQuery query;

ret = query.prepare(QString("UPDATE Table SET Enable = :Enable, Disable = :Disable where id = %1").arg(j));
if(ret)
{
//query.bindValue(":Enable", );
//query.bindValue(":Disable", );
ret = query.exec();

}
}
else
{
QSqlQuery query;
bool ret;
ret = query.prepare(QString("UPDATE Table SET Enable = :Enable, Disable = :Disable where id = %1").arg(j));
if(ret)
{

//query.bindValue(":Enable", );
//query.bindValue(":Disable", );
ret = query.exec();

}
}
j++;
}
}
}

ChrisW67
29th May 2010, 09:06
can any one help me how to change the value in the DB table once we
change the check box in list widget
You change the data by executing an SQL update (or insert or delete)... but clearly you already know that.

You need to explain the problem. What exactly happens when you uncomment and complete the bindValue() calls? Why is that not what you expected? What have you tried to overcome whatever the problem is?

Other observations:

A table named "Table" is likely to be a problem for many RDBMSs
With a bit of re-arrangement you probably only need to prepare the query once
It is really poor etiquette to create a second thread (http://www.qtcentre.org/threads/31141-any-one-have-idea-about-this) to advertise another; doubly so when the original request is barely 12 hours old.

damodharan
29th May 2010, 12:35
thx for all,
problem sloved