2

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?

László Papp
  • 51,870
  • 39
  • 111
  • 135
Daniel
  • 635
  • 1
  • 5
  • 22

1 Answers1

2

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.

László Papp
  • 51,870
  • 39
  • 111
  • 135
  • The [following page](http://qtwiki.remdex.info/How_to_map_QDataWidgetMapper_and_QDateEdit,_QDateTimeEdit_?) is empty and there no information at all. I tried the first way - subclass QSqlRelationaDelegate etc. and it helped, thanks. Can you please explain what do you mean "Extend QDateEdit and make it handle timestamp data and convert to QDate object"? – Daniel Jan 06 '14 at 12:43
  • @ScienceSE: ah, you are right. There was some copy/paste mistake on my side, hehe. It is fixed now, and you can also get more explanation over there about the second solution. – László Papp Jan 06 '14 at 12:45
  • Thanks. But I think that the example in article is incomplete because of NOTIFY dateChanged signal which author forgot to add into his class :) Anyway I've understood the general idea. – Daniel Jan 06 '14 at 13:14