PDA

View Full Version : Update changes in QTableView to sqlite data base



nagabathula
19th April 2011, 06:29
Hello every one, i am working on a project where i display some data from sqlite database in a QTableView widget.. I am having a small problem, wanted to know how i can make QTableView editable and save the changes i make on the QTableView into the sqlite data base.. right now i am doing this i retrieve the data from Sqlite db and display it in the QTableView but i am not able to figure out how i can make it editable and save those changes into the sqilte db..
This is what i am doing to display the data from the sqlite db into QTableView now,


QSqlQuery sqpre("select Channel_Name,TagId,ChannelIndexPosi from tempchnames");
if(sqpre.exec())
{
if (sqpre.first())
{
do
{
temperaturechnames.push_back(sqpre.value(0).toStri ng());
temptagidnames.push_back(sqpre.value(1).toString() );
indexCount.push_back(sqpre.value(2).toString());
} while(sqpre.next());
}
}

QStandardItemModel *model1 ;
model1 = new QStandardItemModel();

QStandardItemModel *model2;
model2 = new QStandardItemModel();

for(int i=0;i< temptagidnames.count(); i++)
{
QStandardItem *item = new QStandardItem(temptagidnames.at(i));
model1->setItem(i, 0, item);
}

for(int j=0;j< temperaturechnames.count(); j++)
{
QStandardItem *item2 = new QStandardItem(temperaturechnames.at(j));
model1->setItem(j, 1, item2);

}



Thank you

nagabathula
19th April 2011, 10:42
Hello some one pls suggest me on how i should go about doing this.. I am stuck not finding what i am looking for in google also..

thank you

b1
12th November 2011, 01:18
nagabathula,

Try using QSqlTableModel instead of a QSqlQuery. I just went through the same process and found that was the trick to be able to edit the data.

B1.