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. Is there a model-view example with a n : m relation?
Forum Updated to NodeBB v4.3 + New Features

Is there a model-view example with a n : m relation?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 1.2k Views 2 Watching
  • 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.
  • P Offline
    P Offline
    pantarhei
    wrote on last edited by pantarhei
    #1

    I am searching a QtWidget example using model-view (delegate) technology to edit database items with a n : m relations.

    An example would be n-persons can attend m-meetings.
    A person can attend 0 to m meetings.
    A meeting can be visited by 0 to n persons.

    A sample how I implement a n : m relation in my database:

    table „person“
    idperson* (int)
    fullname (varchar[50])
    birthdate (date)

    table „meeting“
    idmeeting* (int)
    location (varchar[50])
    startime (timedate)
    endtime (timedate)

    table „person_meeting“
    idperson* (int)
    idmeeting* (int)

    (The '*' shows the primary key colums).

    I prefer C++ and QtWidgets for my desktop application. My application is a „fat client“ / „client-server-application“ with a MySQL database.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      How would you like to do the editing ? You can use e.g. QSqlRelationalTableModel and QTableView or QDataWidgetMapper.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      P 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi and welcome to devnet,

        How would you like to do the editing ? You can use e.g. QSqlRelationalTableModel and QTableView or QDataWidgetMapper.

        Hope it helps

        P Offline
        P Offline
        pantarhei
        wrote on last edited by pantarhei
        #3

        @SGaist I like to have two entry forms.
        One master-detail form where I can create/edit/delete a person (master) and add 0..m meetings the person will attend (detail).
        One master-detail form where I can create/edit/delete a meeting (master) and add 0..n persons which visit the meeting (detail).

        Tree views could be helpfull too. One tree view could be persons as root elements and the meetings attached to them or a tree view where meetings are the root elements and the persons are attached to the persons.

        I assumed QSqlRelationalTableModel or other model-driven widgets was the way to go, but I am open for all kind of solutions.
        I have not looked into QDataWidgetMapper and will learn about it.

        M 1 Reply Last reply
        0
        • P pantarhei

          @SGaist I like to have two entry forms.
          One master-detail form where I can create/edit/delete a person (master) and add 0..m meetings the person will attend (detail).
          One master-detail form where I can create/edit/delete a meeting (master) and add 0..n persons which visit the meeting (detail).

          Tree views could be helpfull too. One tree view could be persons as root elements and the meetings attached to them or a tree view where meetings are the root elements and the persons are attached to the persons.

          I assumed QSqlRelationalTableModel or other model-driven widgets was the way to go, but I am open for all kind of solutions.
          I have not looked into QDataWidgetMapper and will learn about it.

          M Offline
          M Offline
          mjsurette
          wrote on last edited by
          #4

          @pantarhei
          I find that creating views in the database simplifies my code immensely. I use Postgres and use instead of triggers for updates and inserts, so I can use a qsqltableview for a lot. I don't know if MySql can do that though, being unfamiliar with it.

          The QDataWidgetMapper is useful for mapping a single record into a detail form.

          1 Reply Last reply
          1
          • xmilosX Offline
            xmilosX Offline
            xmilos
            wrote on last edited by
            #5

            Hi All,

            i am refering to this topic again and I would like to ask @pantarhei , how did you solve view, editation of database relationship and n:m.

            Thank you

            Milos

            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