Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] QDataWidgetMapper with two models
Forum Update on Monday, May 27th 2025

[Solved] QDataWidgetMapper with two models

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tupla
    wrote on last edited by
    #1

    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
    1 Reply Last reply
    0
    • jensen82J Offline
      jensen82J Offline
      jensen82
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Tupla
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • T Offline
          T Offline
          Tupla
          wrote on last edited by
          #4

          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?

          1 Reply Last reply
          0
          • T Offline
            T Offline
            Tupla
            wrote on last edited by
            #5

            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!

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved