[Qt-interest] QDataWidgetMapper null values/ beforeInsert problem

bar tomas bartomas at gmail.com
Sun Mar 7 19:58:57 CET 2010


Many thanks. Your suggestion works fine.

On Sun, Mar 7, 2010 at 2:55 PM, Mark Brand <mabrand at mabrand.nl> wrote:
>
>> 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
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>




More information about the Qt-interest-old mailing list