PDA

View Full Version : updating database



locus
25th January 2007, 05:07
Does qdatawidgetmapper update databases?

I used the code that can be found at the link below and modified it just to connect to my database(all i did was change "bool createConnections"; nothing else).

http://www.trolltech.com/developer/task-tracker/index_html?method=entry&id=147264

I ran the code and got it to work. I changed


#if 1
model->setEditStrategy(QSqlTableModel::OnFieldChange);
#else
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
#endif


to




#if 0 //changed 1 to 0;thats all
model->setEditStrategy(QSqlTableModel::OnFieldChange);
#else
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
#endif


and the view was updated perfectly; using the mapped lineEdit . But when i go back to the command prompt and check the database, nothing has changed.

Can someone tell me how to update the database using the mapped widget?

My code follows the exact same procedure as that in the link, with only some formatting differences. My mapped widgets does not update the database, the ones in the code at the above URL does not update the database either.

mcosta
25th January 2007, 10:40
Hi,

setting the EditStrategy to QSqlTableModel::OnManualSubmit you must apply the changes with
bool QSqlTableModel::submitAll () or revert them with
void QSqlTableModel::revertAll ().

In this way you can control all changes and apply them to the model only if are consistent with your application logic.

locus
25th January 2007, 17:44
Thanks for the response mcosta.

I should have metioned thought that i tried that (submitAll() that is), but for some reason it did not work

here are the relevant pieces of code that were added to the code found at the URL:




QPushButton *button = new QPushButton("button");

hbox->addWidget(button);

model->setEditStrategy(QSqlTableModel::OnManualSubmit);

connect(button,SIGNAL(clicked()),model,SLOT(submit All()));

mapper.setSubmitPolicy(QDataWidgetMapper::ManualSu bmit);



i then ran the code and and clicked my button to call submitAll(), after pressing CTRl+S to call submit() for the mapper. The attribute value in the view changed, but the value in the database remains untouched.

i found somthing in the docs called :



QAbstractItemDelegate::SubmitModelCache



don't know if it can help, nor do i know how to access the delegate being used by the view to set it.

It is supposed to tell the delegate to write all cached data to the database.

any suggestions will be greatly appreciated.

locus
27th January 2007, 05:54
For a detailed description of the problem and solution got to:


http://www.qtcentre.org/forum/f-qt-programming-2/t-submitall-database-error-5370.html