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. Showing data from multiple SQLite tables

Showing data from multiple SQLite tables

Scheduled Pinned Locked Moved Solved General and Desktop
databasemodel-viewsqlite view
7 Posts 2 Posters 2.5k 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.
  • Pl45m4P Offline
    Pl45m4P Offline
    Pl45m4
    wrote on last edited by Pl45m4
    #1

    I have a SQLite database with 6 tables (some of them with two foreign keys). What would be the easiest solution to create a view to display data (join on multiple tables)?
    I found out, that the QSqlRelationalTableModel works well, but only with one table / one join.
    QSqlQueryModel and QSqlTableModel both dont provide the foreign key support with delegates.

    Is there a way to keep the foreign key support with the possibility of joining data from multiple tables together with simple insertation? How to insert / alter / delete data? Do I have to write querys for every single change?


    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

    ~E. W. Dijkstra

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Just put your query with the joins into a QSqlQueryModel

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      Pl45m4P 1 Reply Last reply
      4
      • Christian EhrlicherC Christian Ehrlicher

        Just put your query with the joins into a QSqlQueryModel

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by Pl45m4
        #3

        @Christian-Ehrlicher

        SqlQueryModel works with Delegates and Relations?
        I dont want to write thousand lines of code just for the querys.
        And I guess you can not change a value there by clicking into the model and start typing?

        From QSqlQueryModel Doc:
        The model is read-only by default. To make it read-write, you must subclass it and reimplement setData() and flags(). Another option is to use QSqlTableModel, which provides a read-write model based on a single database table.

        So I have to code every functionality that e.g. the QSqlRelationalTableModel provides?
        That's a lot of work....


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I don't understand what you mean - you said you want to display data from different tables. So what's wrong writing a query with a join on all columns you want to display and pass t to a QSqlQueryModel?
          Editing such data will not work with any of the convenience QSql*Models in your case - you have to write your own model then.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          Pl45m4P 1 Reply Last reply
          3
          • Christian EhrlicherC Christian Ehrlicher

            I don't understand what you mean - you said you want to display data from different tables. So what's wrong writing a query with a join on all columns you want to display and pass t to a QSqlQueryModel?
            Editing such data will not work with any of the convenience QSql*Models in your case - you have to write your own model then.

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by Pl45m4
            #5

            @Christian-Ehrlicher

            Ok, didn't know that... Thought all Models are editable (Views obviously not)

            Edit: I can edit when I'm using a QSqlRelationalTableModel... this comes very close to what I want / need, but it only works on one table :(


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            0
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              This is what I said - how should the model be able to update data in different tables when they are all joined? This is a task which can't be done generally (at least not for all cases). You have to do it on your own.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              Pl45m4P 1 Reply Last reply
              4
              • Christian EhrlicherC Christian Ehrlicher

                This is what I said - how should the model be able to update data in different tables when they are all joined? This is a task which can't be done generally (at least not for all cases). You have to do it on your own.

                Pl45m4P Offline
                Pl45m4P Offline
                Pl45m4
                wrote on last edited by
                #7

                @Christian-Ehrlicher

                Hm ok... That's not what I wanted to hear :D
                Thank you anyway.
                I think, I will subclass QSqlQueryModel then and write functions to make the model writable...


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                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