PDA

View Full Version : QDataWidgetMapper and QComboBox: Make mapper read currentIndex



hefeweiz3n
18th October 2010, 13:13
Hi. I have the following situation: A QComboBox holds the 7 days of the week. It is filled using the QDate::longDayName() function so i get the dates in the right language. An Additional "select day" entry is inserted at the top so that the indexes correspond with the Dayofweek numbers from Qt.

The model (stored in a db) that i want to change has several fields, the one in question being the "dayofweek" field. For the mapper I tried

mapper->addMapping(ui.comboBox, model->fieldIndex("dayofweek"));
but that doesn't work. What I want it to do is store the current index in the "dayofweek"-column of the model. All other values (lineedits and such) work fine.

How would I go about doing this? The tutorials I found on the web use QRelationalSqlTable as a base but since i want the weekdays internationalised this is not an option.

wysota
18th October 2010, 14:23
Pass "currentIndex" as the third parameter to addMapping().

hefeweiz3n
18th October 2010, 14:33
Thanks, that did the trick.