[Qt-interest] QDataWidgetMapper null values/ beforeInsert problem

Mark Brand mabrand at mabrand.nl
Sun Mar 7 15:55:53 CET 2010


> I'm using a QDataWidgetMapper to map the fields in a database table to
> the fields in a form.
> If a field in the form is left empty I would like a null value to be
> inserted in the database field.
> However, empty fields are given a 0 value for numeric fields and an
> empty string value for text fields by the mapper.
> The mapper seems to ignore the db schema's default declarations.
> I've tried a solution of defining a method activated by the
>   "beforeInsert(QSqlRecord &)" signal that
> explicitely sets the value of the field to null with the setNull
> method of the QSQLRecord class.
> But even this is ignored by the mapper.
> Do you have any hints of a solution to this problem?
> Many thanks
>
>   

QDataWidgetMaper has an item delegate just as a view does. The item
delegate is the link between your widgets and your data model. By
overriding QItemDelegate::setModelData(), you have complete control over
how the values from your widgets are interpreted.

-Mark



More information about the Qt-interest-old mailing list