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. Modifying a cell in TableView using QSqlQueryModel

Modifying a cell in TableView using QSqlQueryModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 201 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.
  • R Offline
    R Offline
    Ray E
    wrote on last edited by
    #1

    I need to query a database and load a tableView. Most of the columns are displayed as in the database. However, one column needs to be changed from a number to a text string.

    The function is very simple. How do I connect this function to the table?

    Thanks

    JonBJ 1 Reply Last reply
    0
    • R Ray E

      I need to query a database and load a tableView. Most of the columns are displayed as in the database. However, one column needs to be changed from a number to a text string.

      The function is very simple. How do I connect this function to the table?

      Thanks

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

      @Ray-E

      • One possibility is a QAbstractProxyModel on top of the SQL model to which the view now attaches which maps the value to a string for the view.
      • Another is a QStyedItemDelegate to do the mapping just for diaply in the view.
      • And a third is if the mapped strings are held in another SQL table to use a QSqlRelationalTableModel if your QSqlQueryModel can be a QSqlTableModel.
      Christian EhrlicherC 1 Reply Last reply
      2
      • JonBJ JonB

        @Ray-E

        • One possibility is a QAbstractProxyModel on top of the SQL model to which the view now attaches which maps the value to a string for the view.
        • Another is a QStyedItemDelegate to do the mapping just for diaply in the view.
        • And a third is if the mapped strings are held in another SQL table to use a QSqlRelationalTableModel if your QSqlQueryModel can be a QSqlTableModel.
        Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @JonB Maybe a QIdentityModel will work also.

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

        JonBJ 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          @JonB Maybe a QIdentityModel will work also.

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

          @Christian-Ehrlicher
          A QIdentityProxyModel is derived from QAbstractProxyModel per my first bullet :) Yes, one would start from a QIPM as an example of a QAPM (does the groundwork for all the identical columns) and just change the one column whose values need mapping.

          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