[Qt-interest] display one database column as two in QTableView
Israel Brewster
israel at frontierflying.com
Mon Mar 8 20:00:43 CET 2010
I have a database which contains a timestamp column. For editing purposes, I want to display this as separate time and date columns. I am using a QSqlTableModel, displayed with a QSqlTableView. How can I make this happen?
My first thought was to subclass QSqlTableModel to expose the setQuery function. I then passed a QSqlQuery like "SELECT date(timestamp_column), time(timestamp_column) FROM table". This worked to display the timestamp column as separate date and time columns. However, when I edited the model and tried to save the changes back to the database, I got a "syntax error around SET".
This might make sense, considering that the model now has two columns whereas the database only has one, so I figured I'd simply override the function that actually writes the data back to the database to manually combine the date and time into a timestamp before submitting the change to the database. It appears to me that the function I need to override is updateRowInTable, but when I tried that it was (apparently at least) never called. Is that the right function to be using?
How can I display a timestamp column as separate date and time columns, and keep it editable? Thanks.
-----------------------------------------------
Israel Brewster
Computer Support Technician II
Era Alaska
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x293
-----------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100308/26c31c09/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Israel Brewster.vcf
Type: text/directory
Size: 417 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100308/26c31c09/attachment.bin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100308/26c31c09/attachment-0001.html
More information about the Qt-interest-old
mailing list