PDA

View Full Version : QDataWidgetMapper AutoSubmit



jeffpogo
19th January 2010, 18:01
QDataWidgetMapper Qt Documentation: "AutoSubmit" will update the model as soon as the current widget loses focus."

What exactly does "loses focus" mean?

When I update a field in my form it calls the "setModelData" function the first time but if I re-enter the same field and try to update it again -- the "setModelData" is NOT called to update to the new value.

Can someone explain when the QDataWidgetMapper is supposed to update the model in "AutoSubmit" mode?

Do most people use AutoSubmit? (I am sure Manual Submit will work, but AutoSubmit would be cleaner -- no button press required.)

Thanks, Jeff.

axeljaeger
19th January 2010, 22:58
Expected behaviour is that when you click inside a cell, edit starts. When you click outside, so editor widget looses focus, the model should be updated. Qt comes with an example how to use the QDataWidgetMapper. See examples/itemviews/simplewidgetmapper and see whether it behaves the same.

jeffpogo
20th January 2010, 14:30
Thanks!

I got it working ... I had a bad signal call in my setEditorData function.

Jeff.

jeffpogo
27th January 2010, 20:59
The QDataWidgetMapper/QSqlTableModel/AutoSubmit combination do not seem to work together as expected. When you change focus, sometimes the model gets updated, sometimes it does not. (Usually the first field gets updated -- the first time and the others do not.)

I might be able to get my form working correctly with the suggestion in QTBUG-1086. (I might try it.)

I would venture that most people code there own form mapping solution.

I learned a lesson ... when something is not working as you expect check: http://bugreports.qt.nokia.com/browse -- it can save a lot of time.

If someone does have some successful QDataWidgetMapper/QSqlTableModel code they would like to share, I would love to check it out because I like the concept.

schnitzel
27th January 2010, 22:15
I had some trouble with the QDataWidgetMapper/QSqlTableModel. I'm using them in manualsubmit mode as the auto mode has some weirdness as you indicated.

What worked for me is the following:



//inside constructor
model = new QSqlTableModel;
model->setTable("unit");
model->setEditStrategy(QSqlTableModel::OnManualSubmit);

model->select();
model->sort(3,Qt::AscendingOrder);

mapper = new QDataWidgetMapper(this);
mapper->setModel(model);
mapper->addMapping(ui->le_Unit, model->fieldIndex("UnitName"));

....

//inside a method where I make some changes to the mapped items
mapper->submit();
model->submitAll();



hope this helps