Results 1 to 2 of 2

Thread: Database does not update when using QSqlRelationalTableModel and setRelation

  1. #1
    Join Date
    Jun 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Database does not update when using QSqlRelationalTableModel and setRelation

    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?

  2. #2
    Join Date
    Jun 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Database does not update when using QSqlRelationalTableModel and setRelation

    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?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.