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. Comparing a QList<QStringList> and the contents of a QTableWidget

Comparing a QList<QStringList> and the contents of a QTableWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 524 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.
  • Dummie1138D Offline
    Dummie1138D Offline
    Dummie1138
    wrote on last edited by
    #1

    I am building a save button and I want a popup that shows up when the user leaves the page containing the QTableWidget, if the information in the QTableWidget has not yet been saved to an SQL database. Therefore, I would like to compare the contents of the QTableWidget and that of the SQL data, represented in a QList<QStringList>. I am wondering whether there are any functions in QTableWidget that recovers the QStrings in the QTableWidget. and compiles them into a QStringList or a QList. Failing that, any other methods of comparing the contents of a QTableWidget and a QList<QStringList> would also be welcome.

    JonBJ 1 Reply Last reply
    0
    • Dummie1138D Dummie1138

      I am building a save button and I want a popup that shows up when the user leaves the page containing the QTableWidget, if the information in the QTableWidget has not yet been saved to an SQL database. Therefore, I would like to compare the contents of the QTableWidget and that of the SQL data, represented in a QList<QStringList>. I am wondering whether there are any functions in QTableWidget that recovers the QStrings in the QTableWidget. and compiles them into a QStringList or a QList. Failing that, any other methods of comparing the contents of a QTableWidget and a QList<QStringList> would also be welcome.

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

      @Dummie1138
      No, QTableWidget does not have anything for its data to do with lists or string lists. Just write the code to do whatever comparison you want.

      Incidentally, it does not sound good if your are using a QTableWidget to deal with data in a database. The most convenient way is to use the QSql... classes for the data tables and a QTableView for the display, which can be tied to your SQL model.

      Dummie1138D 1 Reply Last reply
      2
      • JonBJ JonB

        @Dummie1138
        No, QTableWidget does not have anything for its data to do with lists or string lists. Just write the code to do whatever comparison you want.

        Incidentally, it does not sound good if your are using a QTableWidget to deal with data in a database. The most convenient way is to use the QSql... classes for the data tables and a QTableView for the display, which can be tied to your SQL model.

        Dummie1138D Offline
        Dummie1138D Offline
        Dummie1138
        wrote on last edited by
        #3

        @JonB I wasn't aware that QTableView can be tied to a SQL database, nor did I found any documentation on the QTableView documentation for this matter. Would you happen to know where this information may be stored?

        jsulmJ JonBJ 2 Replies Last reply
        0
        • Dummie1138D Dummie1138

          @JonB I wasn't aware that QTableView can be tied to a SQL database, nor did I found any documentation on the QTableView documentation for this matter. Would you happen to know where this information may be stored?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Dummie1138 https://doc.qt.io/qt-6/sql-presenting.html

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • Dummie1138D Dummie1138

            @JonB I wasn't aware that QTableView can be tied to a SQL database, nor did I found any documentation on the QTableView documentation for this matter. Would you happen to know where this information may be stored?

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

            @Dummie1138
            Qt's QTableView can view/edit anything which supplies the QAbstractItemModel model interface.

            • QSqlQueryModel provides a read-only model for an arbitrary SELECT query.
            • QSqTableModel provides a read/write model for a SQL TABLE.
            • QTableView can have either of these as its setModel(). It allows update editing for the latter one.
            • QTableWidget is a "convenience" widget. It derives from QTableView but provides its own in-memory simple model.

            If you use QTW with SQL you will be copying values between the query results and the inbuilt model. If you use QTV you will be accessing the SQL model directly.

            1 Reply Last reply
            2

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved