QDataWidgetMapper and QDateEdit values

928 views Asked by At

I have QSqlTableModel with some table, let's suppose that it's a

model->setTable("Person");

And also I have QDataWidgetMapper which mapps some widgets (lineedits etc.) to appropriate columns in model.
So the problem is in QDateEdit element.

mapper->addMapping(birthEdit, Person_Birthdate);

When I change the date in birthEdit (QDateEdit) the values isn't actually changed in appropriate table because they are stored in a different format, and I also get an error:

"QODBCResult::exec: unable to bind variable: "[Microsoft][ODBC SQL Server Driver]...".

The date in database is stored in "yyyy-MM-dd" while the QDateEdit returns the date in another (I suppose). As far as I know QDataWidgetMapper uses USER property in mapped widget to get/set the value.

How can I solve my problem?

1

There are 1 answers

3
László Papp On BEST ANSWER

You have two approaches to be taken as per the following page:

  • Subclass QSqlRelationalDelegate and make appropriate changes in setEditorData and setModelData methods.

  • Extend QDateEdit and make it handle timestamp data and convert to QDate object.