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. MultipleModels/oneView
Forum Updated to NodeBB v4.3 + New Features

MultipleModels/oneView

Scheduled Pinned Locked Moved General and Desktop
21 Posts 14 Posters 13.8k 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.
  • I Offline
    I Offline
    ixSci
    wrote on last edited by
    #11

    [quote]and I will be obliged to make a custom QTableView [/quote]
    Why? If you have custom model it doesn't force you to create your own view as long as your model inherits QAbstractItemModel.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #12

      It does not make any sense that a (Table)View works on more than one model. From both a programmers and a users view this is not intuitive and error prone.

      As Gerolf already suggested, it's the best to make either your own ItemViewModel or try to combine the existing ones (you can add more than one table to QSqlRelationalTableModel).

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fcrochik
        wrote on last edited by
        #13

        It seems that you are gathering data from a database. If that is the case and you just need a read-only view you can just combine the data sources (tables) on your sql statement and use a QSqlQueryModel

        Certified Specialist & Qt Ambassador <a href="http://www.crochik.com">Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop... Qt everywhere!</a>

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vcsala
          wrote on last edited by
          #14

          [quote author="syrianzoro" date="1293645179"]but this is the maximum number of tables you can use at the same time ,you can use two tables.[/quote]

          Actually it is not true, the number of the tables is not limited. You have a master table which has several foreign keys to other tables and you can set all the relations to those tables. If you want to do a read/write model it is recommended to use the QSqlRelationalDelegate.

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nasit.bhavin
            wrote on last edited by
            #15

            I have same question. I have tableview and I want to display multiple tables from MYSQL on same view at a time. Is there any solution exist without creating custom model/view??

            1 Reply Last reply
            0
            • N Offline
              N Offline
              nasit.bhavin
              wrote on last edited by
              #16

              No Solutions..!!!

              1 Reply Last reply
              0
              • A Offline
                A Offline
                AllenB2012
                wrote on last edited by
                #17

                I agree with fcrochik. Create a view in SQL server with all of you related data, test it from the SQL sandbox and use it.

                1 Reply Last reply
                0
                • W Offline
                  W Offline
                  wrosecrans
                  wrote on last edited by
                  #18

                  [quote author="nasit.bhavin" date="1372075788"]I have same question. I have tableview and I want to display multiple tables from MYSQL on same view at a time. Is there any solution exist without creating custom model/view??[/quote]

                  For the people who have multiple tables, are they the same set of columns and such? If so, why are they separate tables? And can you do an SQL query which presents all of your tables as a view? Because joining completely arbitrary tables in a single view would tend to be a non sensical thing to do. I am trying to understand the use case that people are looking for. I mean you can't sort a column on half bool's and half datestamps in a way that is particularly intuitive. Likewise, how do you define rowCount() in a model that has models with differing rowCounts. I can't see any general purpose way to do it that would make everybody happy. Merging models into a single model seems like a very application specific sort of task.

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    plinioandrade
                    wrote on last edited by
                    #19

                    Hey Volker,
                    I don't understand why you said it's confusing and not usual! Let's say I have a table for customer and other one for address and the address table has some fields like 'zip_code', 'city','state' and so on. What should I do if I want to show a TableView with the complete information about customers? The QSqlRelationalTableModel just allow me to link a foreign key to a field on other table but in fact I want to link one foreign key to other table and show all fields of that table. Does someone have a solution?

                    S 1 Reply Last reply
                    1
                    • P plinioandrade

                      Hey Volker,
                      I don't understand why you said it's confusing and not usual! Let's say I have a table for customer and other one for address and the address table has some fields like 'zip_code', 'city','state' and so on. What should I do if I want to show a TableView with the complete information about customers? The QSqlRelationalTableModel just allow me to link a foreign key to a field on other table but in fact I want to link one foreign key to other table and show all fields of that table. Does someone have a solution?

                      S Offline
                      S Offline
                      seyed
                      wrote on last edited by
                      #20

                      @plinioandrade said in MultipleModels/oneView:

                      Hey Volker,
                      I don't understand why you said it's confusing and not usual! Let's say I have a table for customer and other one for address and the address table has some fields like 'zip_code', 'city','state' and so on. What should I do if I want to show a TableView with the complete information about customers? The QSqlRelationalTableModel just allow me to link a foreign key to a field on other table but in fact I want to link one foreign key to other table and show all fields of that table. Does someone have a solution?

                      Any solution?

                      VRoninV 1 Reply Last reply
                      0
                      • S seyed

                        @plinioandrade said in MultipleModels/oneView:

                        Hey Volker,
                        I don't understand why you said it's confusing and not usual! Let's say I have a table for customer and other one for address and the address table has some fields like 'zip_code', 'city','state' and so on. What should I do if I want to show a TableView with the complete information about customers? The QSqlRelationalTableModel just allow me to link a foreign key to a field on other table but in fact I want to link one foreign key to other table and show all fields of that table. Does someone have a solution?

                        Any solution?

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

                        @seyed Write the SQL query with all the relations you need and run it using QSqlQuery then populate a QStandardItemModel with the results

                        "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