PDA

View Full Version : Getting model to submit data when using QDataWidgetMapper



Mookie
19th January 2008, 15:42
When using QDataWidgetMapper one can trigger a submit() in the model, which I have verified is happening. My model happens to be QSqlQueryModel.

How is my model supposed to get the current values and see if they have "changed"? Either it gets them directly from the widgets or the mapper. I would expect the mapper to help some here, since it is the go-between.

wysota
19th January 2008, 18:14
The question is a bit strange... The model holds the data thus knowing "current" values is just a matter of looking into its data structures. If you want to find which data needs submiting, then your model needs to track that for example by setting some flag on the data from its setData() method and clearing that flag when the data is submitted into the storage.

The data widget mapper's submit() call submits the data from the mapper to the model. Calling model's submit() at that moment is only a side effect. The whole logic is inside the mapper that probably just calls setData() on each mapped column/row widget that has the modified flag set.

Mookie
21st January 2008, 00:11
I added some output to both the mapper and the model verifying that submit() is being called on both. QSqlQueryModel::setData() is not being called, so if the QDataWidgetMapper has that responsibility then I have missed a configuration option somewhere.

I think the mapper merely calls submit() on the model and leaves it up to the model to change any data that needs changing.

wysota
21st January 2008, 12:22
QSqlQueryModel is a read only model. It won't call setData().