QDataWidgetMapper and formatting date/time
There is currently an "order date" column table in a SQLite DB which holds the string "2011-08-21", when that column is mapped (via QDataWidgetMapper) to a QDateEdit, it is not parsing the string into a date correctly. Is there some way to control the formatting in this situation?
Side note, if it matters: In the next 6-month the DB is going to be converted from SQLite to Firebird.
dangelog last edited by
I think the easiest way would be creating a custom QItemDelegate subclass, and override setEditorData and setModelData. In those you can check (qobject_cast) if you're getting/setting data from/to the QDateEdit, and properly convert the string to a QDate or vice-versa.
Well, I like the idea, but... I don't see setItemDelegate on the QDateEdit widget. How do I set a custom delegate on the QDateEdit?
I get it, I set the delegate on the QDataWidgetMapper.
goetz last edited by
Just for the records:
Unfortunately, SQLite does not provide a native date/time type. It is usually mapped into a string columns (like in your case) or an int or double typed column (usually holding seconds since epoch = 1970-01-01 00:00:00 GMT).
Ah, I see you got that string to date conversion already and just search for the proper way to inject that beast.