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. What to subclass?

What to subclass?

Scheduled Pinned Locked Moved Solved General and Desktop
qsqlquerymodelsubclassingmodel-vieweditable model
9 Posts 2 Posters 1.4k 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

    Hi,

    currently I'm subclassing QSqlQueryModel to get an editable model (data comes from SQLite DB).
    I select the "base"-data with a QSqlQuery at the moment, but now I need to insert columns manually, because I want to show data, which is calculated on runtime (not in DB).
    Somewhere I've read that I need to subclass QAbstractItemModel or QAbstractTableModel for this. But I think, I'm losing the Query functionality then, dont I?

    The next thing I'm thinking of, is using some widgets like QComboBox inside the model to select between given values, when editing.

    So basically:

    • Model shows data from DB (multiple tables), currently by executing a QSqlQuery
    • user clicks an editable cell (where "editable" flag was set), if cell contains digits (int type) -> ComboBox with valid numbers is shown,
    • user can select value, on "enter" or something like that, the comboBox value is written to the db / model,
    • the ComboBox disappears afterwards and the new value is shown inside the model.

    How to insert these values to my db, when I dont have queries anymore?

    I dont know if all these features are possible by sublassing one given Model-class or how else I can implement this.

    Any help or code examples appreciated :)

    EDIT:
    The view is a QTableView (tables are joined). I guess I have to change the view as well (to use comboBoxes for editing)?!


    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 Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @pl45m4 said in What to subclass?:

      when I dont have queries anymore?

      What prohibits you to use a QSqlQuery within your custom class derived from QAbstractItemModel?

      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
      0
      • Christian EhrlicherC Christian Ehrlicher

        @pl45m4 said in What to subclass?:

        when I dont have queries anymore?

        What prohibits you to use a QSqlQuery within your custom class derived from QAbstractItemModel?

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

        @christian-ehrlicher

        I assumed that QAbstractItemModel provides no setQuery(). So I have to write my own function to execute a QSqlQuery?


        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 Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @pl45m4 said in What to subclass?:

          So I have to write my own function to execute a QSqlQuery?

          Yes

          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
          0
          • Christian EhrlicherC Christian Ehrlicher

            @pl45m4 said in What to subclass?:

            So I have to write my own function to execute a QSqlQuery?

            Yes

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

            @christian-ehrlicher

            Is there any other way to get data from SQLite database with Qt except queries?
            Implementing the functionality to use SQL queries is not what I what to do. It sounds very complicated or is it not that hard?


            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 Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              I don't see what's complicated executing a QSqlQuery and fetching the data. Especially compared to the idea to parse the data somehow from a sqlite file...

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

              Pl45m4P 2 Replies Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                I don't see what's complicated executing a QSqlQuery and fetching the data. Especially compared to the idea to parse the data somehow from a sqlite file...

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

                @christian-ehrlicher said in What to subclass?:

                I don't see what's complicated executing a QSqlQuery and fetching the data.

                Because I cannot add the calculated data to my model, if I use a QSqlTableModel subclass, so I thought I can subclass QAbstractTableModel or QAbstractItemModel but setQuery() is implemented first in QSqlTableModel.

                EDIT:
                You mean executing the query to get the data from DB, without setting the data to the model directly?
                So I can execute the query to get my "base"-data, then calculate the missing cols and then set the data to the model?


                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 Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @pl45m4 said in What to subclass?:

                  You mean executing the query to get the data from DB, without setting the data to the model directly?

                  Yes

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

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    I don't see what's complicated executing a QSqlQuery and fetching the data. Especially compared to the idea to parse the data somehow from a sqlite file...

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

                    @christian-ehrlicher said in What to subclass?:

                    Especially compared to the idea to parse the data somehow from a sqlite file

                    Where I have said that? :)
                    I never had the idea to "parse" the sqlite file directly.

                    I will try to get the data with a query first and see what I can do with it :)
                    (I guess QSqlResult is the key?!)


                    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