[Solved] QDataWidgetMapper with two models



  • Hi, I am writing an application which uses a SQLite database in order to store data. The database is made of three tables:

    • Owner (general information about a vehicle's owner).
    • Vehicle (general information about a vehicle).
    • Deadlines (information about specific and optional deadlines for each vehicle).
      Insertion and deletion work without problem, now I am thinking of how to edit data. I would like to use a QDataWidgetMapper in order to edit vehicle's information, owner, and deadlines.
      The problem is that I can't use a QSqlRelationalTableModel, because there's a relation between vehicle and owner tables, and one between deadlines and vehicle tables.
      How can I fill the mapper widget with data if they are taken from different tables, and if it's possible, are they editable?
      Thanks


  • Hm...i think you need a master/detail-view (and replace the table with QDataWidgetMapper).
    Look at the examples (examples\sql\masterdetail), it's a good example for that.

    Or is the problem that you can't handle QSqlRelationalTableModel?



  • The problem is that I would like to edit not only the vehicle's information, but also its deadlines in the same widget.
    For example, if I want to edit the owner of the vehicle, I need a QSqlRelationalTableModel in my widget mapper (because "vehicle" table has a foreign key for the owner), and that's fine. But if I also want to edit a vehicle's deadlines I need a second QSqlRelationalTableModel (because there's a relation between "deadlines" table and "vehicle"). My question is: How can I combine the two things, and edit data from two tables ("vehicle" and "deadlines") instead of one? What model have I to use in order to do that, if it's possible?



  • I found a solution to this problem, I simply used two mapper widget with two different models.

    EDIT: no, it isn't solved, it does not submit data... Any ideas?



  • Ok, it's solved, I messed up something with manual submit of the two models, setting their policy to "OnRowChange" made the whole thing working. Thanks a lot anyway!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.