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. [QTableView remove selected rows?
Forum Updated to NodeBB v4.3 + New Features

[QTableView remove selected rows?

Scheduled Pinned Locked Moved Solved General and Desktop
qt4.8
27 Posts 4 Posters 29.4k 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.
  • V Offline
    V Offline
    VRonin
    wrote on 2 May 2017, 13:45 last edited by VRonin 5 Feb 2017, 13:52
    #11

    from http://doc.qt.io/qt-5/qsqlquerymodel.html:

    The QSqlQueryModel class provides a read-only data model for SQL result sets.

    Since it's read only it does not allow you to delete rows

    "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
    0
    • V Offline
      V Offline
      veera
      wrote on 2 May 2017, 13:56 last edited by
      #12

      Then which model i need to use and how to do it please give me some examples ........

      1 Reply Last reply
      0
      • V Offline
        V Offline
        VRonin
        wrote on 2 May 2017, 14:05 last edited by
        #13

        either QSqlTableModel (be carefull with this one, read the docs) or you manually populate a QStandardItemModel from the data you get from a QSqlQuery

        "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
        0
        • V Offline
          V Offline
          veera
          wrote on 2 May 2017, 14:36 last edited by
          #14

          give me some examples so that i can understand it better

          1 Reply Last reply
          0
          • V Offline
            V Offline
            VRonin
            wrote on 2 May 2017, 14:42 last edited by VRonin 5 Feb 2017, 14:43
            #15

            QStandardItemModel + QSqlQuery https://forum.qt.io/topic/76135/qsqlrelationaltablemodel-and-complex-queries/21

            QSqlTableModel http://doc.qt.io/qt-5/qsqltablemodel.html#details

            "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
            3
            • V Offline
              V Offline
              veera
              wrote on 2 May 2017, 15:11 last edited by
              #16

              Its not happening ....... i have selected one and tried but its not deleting and tried many rows also not deleting my database is MSSQL in Ubuntu.....

              1 Reply Last reply
              0
              • V Offline
                V Offline
                VRonin
                wrote on 2 May 2017, 15:30 last edited by
                #17

                30 minutes before giving up?

                create a dummy table in your database (so even in case of a disaster you won't lose anything important) and try with QSqlTableModel

                "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
                0
                • V Offline
                  V Offline
                  veera
                  wrote on 3 May 2017, 05:41 last edited by
                  #18

                  I want to something this type of query
                  query->prepare("DELETE FROM Info WHERE ID = ?");
                  query->addBindValue(ID);
                  for deleting of entire row by selecting a particular row...........

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    VRonin
                    wrote on 3 May 2017, 07:12 last edited by
                    #19

                    QSqlTableModel or QSqlRelationalTableModel does that for you if you can live with simple queries. if you have convoluted joins then you'll have to connect to the model rowsRemoved or rowsAboutToBeRemoved signal and prepare the query manually

                    "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

                    V 1 Reply Last reply 3 May 2017, 07:32
                    1
                    • V VRonin
                      3 May 2017, 07:12

                      QSqlTableModel or QSqlRelationalTableModel does that for you if you can live with simple queries. if you have convoluted joins then you'll have to connect to the model rowsRemoved or rowsAboutToBeRemoved signal and prepare the query manually

                      V Offline
                      V Offline
                      veera
                      wrote on 3 May 2017, 07:32 last edited by
                      #20

                      @VRonin
                      I am a beginner of MS SQL so please give me examples

                      1 Reply Last reply
                      0
                      • V Offline
                        V Offline
                        VRonin
                        wrote on 3 May 2017, 07:34 last edited by
                        #21

                        ... it's included as part of Qt's examples: http://doc.qt.io/qt-5/qtsql-relationaltablemodel-example.html

                        "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
                        • V Offline
                          V Offline
                          veera
                          wrote on 3 May 2017, 09:07 last edited by
                          #22

                          i go through the examples in that they creating QTableView *view = new QTableView; but i am designed in the UI drag and drop of Tableview and everything so.........

                          1 Reply Last reply
                          0
                          • V Offline
                            V Offline
                            VRonin
                            wrote on 3 May 2017, 09:19 last edited by VRonin 5 Mar 2017, 09:19
                            #23

                            There is absolutely no difference. The trag and drop in Qt Designer generates an xml file describing your interface then uic converts that xml into code basically identical to the one in the examples.

                            On top of this, your problem is not in the UI but in the model design so you should not really care about how the UI is created

                            "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
                            0
                            • V Offline
                              V Offline
                              veera
                              wrote on 3 May 2017, 12:34 last edited by
                              #24

                              I go through those examples ,explaining the inserting data into the tableview but they did not explain the deleting particular row after selecting it........

                              1 Reply Last reply
                              0
                              • V Offline
                                V Offline
                                veera
                                wrote on 3 May 2017, 12:39 last edited by
                                #25

                                through out my project i am using this model
                                QSqlQueryModel *model = new QSqlQueryModel;
                                its happening by executing qurey by passing id via line edit but i am trying selecting entire row and pressing delete is not happening ......

                                1 Reply Last reply
                                0
                                • V Offline
                                  V Offline
                                  VRonin
                                  wrote on 4 May 2017, 07:04 last edited by
                                  #26

                                  QSqlQueryModel is read only. you cannot delete, insert or change anything

                                  "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
                                  0
                                  • V Offline
                                    V Offline
                                    veera
                                    wrote on 5 May 2017, 04:52 last edited by
                                    #27

                                    with this model only i am inserting and updating data into qtableview but delete is not happening ?,if u want i can share the code insert and updating data .......

                                    1 Reply Last reply
                                    0

                                    20/27

                                    3 May 2017, 07:32

                                    • Login

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