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. QSqlRelationalTableModel or QSqlQueryModel

QSqlRelationalTableModel or QSqlQueryModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 1.6k 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.
  • M Offline
    M Offline
    michaeldev
    wrote on last edited by
    #1

    Hi!

    Description:
    I use QTableView with database in first form for listing records.
    I create second form (modal form) for editing single record. This record has field, referencing to other table (FK). I tried to use QSqlRelationalTableModel with "setFilter" (for selecting single record) and "setRelation" (for processing FK and combobox). I planned to use "submit" for saving record.
    I didn't have success with this scheme because "setFilter" and "setRelation" are conflicting. I think I should use QSqlQueryModel for selecting single record.

    Questions:
    How should I save record (QSqlQueryModel is read-only)?
    Is this method right and the best for my target?

    VRoninV 1 Reply Last reply
    0
    • M michaeldev

      Hi!

      Description:
      I use QTableView with database in first form for listing records.
      I create second form (modal form) for editing single record. This record has field, referencing to other table (FK). I tried to use QSqlRelationalTableModel with "setFilter" (for selecting single record) and "setRelation" (for processing FK and combobox). I planned to use "submit" for saving record.
      I didn't have success with this scheme because "setFilter" and "setRelation" are conflicting. I think I should use QSqlQueryModel for selecting single record.

      Questions:
      How should I save record (QSqlQueryModel is read-only)?
      Is this method right and the best for my target?

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      @michaeldev said in QSqlRelationalTableModel or QSqlQueryModel:

      I think I should use QSqlQueryModel for selecting single record

      No, you can just use a QSortFilterProxyModel on the original model and your strategy will work

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      M 1 Reply Last reply
      1
      • VRoninV VRonin

        @michaeldev said in QSqlRelationalTableModel or QSqlQueryModel:

        I think I should use QSqlQueryModel for selecting single record

        No, you can just use a QSortFilterProxyModel on the original model and your strategy will work

        M Offline
        M Offline
        michaeldev
        wrote on last edited by
        #3

        @VRonin Yes, I've try and it works.
        But now I am facing with problem of saving changes. QDataWidgetMapper doesn't update ComboBox after changing.
        I see the same situation here
        https://forum.qt.io/topic/63442/sql-widget-mapper-example-weirdness
        And there is bugreport
        https://bugreports.qt.io/browse/QTBUG-50780

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          You can still implement what QDataWidgetMapper does manually. I know it's not ideal but it shouldn't be a huge amount of work

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          M 1 Reply Last reply
          1
          • VRoninV VRonin

            You can still implement what QDataWidgetMapper does manually. I know it's not ideal but it shouldn't be a huge amount of work

            M Offline
            M Offline
            michaeldev
            wrote on last edited by
            #5

            It is very strange. Components are very raw. At least some of them.

            VRoninV 1 Reply Last reply
            0
            • M michaeldev

              It is very strange. Components are very raw. At least some of them.

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              @michaeldev said in QSqlRelationalTableModel or QSqlQueryModel:

              Components are very raw

              I wouldn't be that harsh. There are a few bugs here and there and some parts have been more-or-less discontinued (DOM qgraphicsview, etc.) but overall the quality of components in Qt is pretty high

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              0
              • M Offline
                M Offline
                michaeldev
                wrote on last edited by
                #7

                Qt Widgets - more alive than dead or more dead than alive?

                VRoninV 1 Reply Last reply
                0
                • M michaeldev

                  Qt Widgets - more alive than dead or more dead than alive?

                  VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #8

                  It's a vital part of the framework so I'd say alive

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  1 Reply Last reply
                  1

                  • Login

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