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. Getting QSqlRelationalTableModel from QSqlRelationalTableModel
Forum Updated to NodeBB v4.3 + New Features

Getting QSqlRelationalTableModel from QSqlRelationalTableModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 1.0k Views 1 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.
  • J Offline
    J Offline
    Jendker
    wrote on last edited by
    #1

    Hi!

    I am using very good example 'sqlwidgetmapper' to get the idea how to get the relation model from QSqlRelationalTableModel. The thing is, that in my case I would need to create a chain so that I would need to create relation for the relation model, but QSqlRelationalTableModel::relationModel(int column) will return only the pointer to QSqlTableModel. This prevents the whole concept of relation for the new returned model.

    What could be the solution for it? I was checking all the examples and searching the internet but did not find reasonable solution...

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

      Hi,

      Can you give more details about your database schema ?

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

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jendker
        wrote on last edited by
        #3

        I will be using the following database:

        • 'producer' table with primary key (varchar, I guess this is not a problem with QSQLITE) and (among the others) key, which will relate to 'article' table
        • 'article' table with key (should I use primary key?) and the key, which will relate 'colour' table'
        • 'colour' table will have the key and the name of the colour

        I would like to be able to present nicely the combo box with the color names using the QSqlWidgetMapper depending on the current 'producer' id, which will have the assigned current 'article' id, which will in turn relate to 'colour' table with the current colour id.

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

          It's a bit unclear what you want to show on your GUI. Can you post a sketch of it ?

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

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Jendker
            wrote on last edited by
            #5

            Basically it would be important for me to get all the TableModels as the QSqlRelationalTableModel. One additional reason is that I would like to subclass the QSqlRelationalTableModel and doing it separately for QSqlTableModel and QSqlRelationalTableModel would be inconvenient. So I would like to be able to get somehow QSqlRelationalTableModel from the columns of the QSqlRelationalTableModel, not only QSqlTableModel (if possible).

            What I want to achieve on the example with articles:
            in 'article' table I would have a colour id specified for each article (please have a look on the list on the tables in the post above). The color id would then relate to the specific colour from the 'colour' table, which would be shown in the table view in the corresponding column. This could be easily done with a simple relation, but if I am getting the 'article' table from 'producer' table using the QSqlRelationalTableModel::relationModel function I would get only QSqlTableModel, which would prevent me from setting any relations.

            If that still would not be clear enough, please let me know.

            JonBJ 1 Reply Last reply
            0
            • J Jendker

              Basically it would be important for me to get all the TableModels as the QSqlRelationalTableModel. One additional reason is that I would like to subclass the QSqlRelationalTableModel and doing it separately for QSqlTableModel and QSqlRelationalTableModel would be inconvenient. So I would like to be able to get somehow QSqlRelationalTableModel from the columns of the QSqlRelationalTableModel, not only QSqlTableModel (if possible).

              What I want to achieve on the example with articles:
              in 'article' table I would have a colour id specified for each article (please have a look on the list on the tables in the post above). The color id would then relate to the specific colour from the 'colour' table, which would be shown in the table view in the corresponding column. This could be easily done with a simple relation, but if I am getting the 'article' table from 'producer' table using the QSqlRelationalTableModel::relationModel function I would get only QSqlTableModel, which would prevent me from setting any relations.

              If that still would not be clear enough, please let me know.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @Jendker
              I could be off-base on this, but since QSqlTableModel *QSqlRelationalTableModel::relationModel(int column) const is virtual, and QSqlRelationalTableModel is derived from QSqlTableModel, could you not override that in your own derived class and return some other existing QSqlRelationalTableModel of your own?

              You won't get a QSqlRelationalTableModel from the base QSqlRelationalTableModel::relationModel() because it only requires the FK table to be a plain QSqlTableModel.

              J 1 Reply Last reply
              0
              • JonBJ JonB

                @Jendker
                I could be off-base on this, but since QSqlTableModel *QSqlRelationalTableModel::relationModel(int column) const is virtual, and QSqlRelationalTableModel is derived from QSqlTableModel, could you not override that in your own derived class and return some other existing QSqlRelationalTableModel of your own?

                You won't get a QSqlRelationalTableModel from the base QSqlRelationalTableModel::relationModel() because it only requires the FK table to be a plain QSqlTableModel.

                J Offline
                J Offline
                Jendker
                wrote on last edited by
                #7

                @JonB Thank you! I will give it a try!

                Maybe to explain my problem in a bit different way: I hang up on the creation of the TableModel using the QSqlRelationalTableModel::relationModel(int column) because I would like to get something similar like done in this example: allow selection of the colour from the 'colour' table, which will relate to selected 'article', in relation to 'producer'. That makes article model the usual QSqlTableModel, which prevents me from using the relation. But at the same time I am not pretty sure if the convenctional creation of the separate QSqlRelationalTableModel for the 'article' table would be somehow better then creation of the whole chain of the 3 tables using QSqlRelationalTableModel::relationModel(int column)...

                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