PDA

View Full Version : Database does not update when using QSqlRelationalTableModel and setRelation



xinevil
7th June 2008, 18:11
If I use a QSqlRelationalTableModel for representing a PostgreSQL database and then use QSqlRelationalTableModel::setRelation to set a foreign key, the data in the database isn't updated when I edit data in a tableView. If I remove the call to QSqlRelationalTableModel::setRelation everything works fine, but then I don't have dropdowns for the foreign data. I'm using Qt 4.3.5.

Does anyone else have this problem or know a solution?

xinevil
7th June 2008, 18:29
Ok I found a bit more. The table does not have a primary key (and it isn't very easy for me to add it, because it is not my own database, so I can not easily alter it). When the db doesn't have a primary key, Qt will create an update query which contains every column in the where clause. But if there are relations, Qt doesn't understand that and uses (I think) the name of the "foreign" table as a field name, which obviously doesn't exist in my table.
Is there a way to change this behaviour?