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. Removing rows from TableModel

Removing rows from TableModel

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 4.2k 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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 1 Oct 2017, 21:45 last edited by
    #2

    Hi and welcome to devnet,

    Just to be sure I understand your question correctly, are you asking us to review your code and explain it to you ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    T 1 Reply Last reply 3 Oct 2017, 12:22
    1
    • S SGaist
      1 Oct 2017, 21:45

      Hi and welcome to devnet,

      Just to be sure I understand your question correctly, are you asking us to review your code and explain it to you ?

      T Offline
      T Offline
      theo_ld
      wrote on 3 Oct 2017, 12:22 last edited by
      #3

      @SGaist I said this code was coming from Qt Address Book Example. I've tried it, but I'd like to change some features.
      By the way, i'm not sure to understand how the TableModel works. I tried to clear it but

      table->removeRows(0, table->rowCount(QModelIndex()));
      

      doesn't work. So yes, can you clarify me this example ?

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JonB
        wrote on 3 Oct 2017, 12:50 last edited by JonB 10 Mar 2017, 12:52
        #4

        @theo_ld

        table->removeRows(0, table->rowCount(QModelIndex()));
        

        doesn't work. So yes, can you clarify me this example ?

        What does "doesn't work" mean? Compile error? Runtime error? Not the behaviour you expected? ...

        1. What is your table->editStrategy()? Docs state that only OnManualSubmit allows mutliple-row deletion. And then you'll need a submitAll().
        2. Check the return result of your table->removeRows(), and lastError() if that's false.
        3. I think table->clear() is a quick way of deleting all rows, though that may not affect what you are wanting to learn about.
        1 Reply Last reply
        0
        • T Offline
          T Offline
          theo_ld
          wrote on 3 Oct 2017, 12:56 last edited by theo_ld 10 Mar 2017, 13:03
          #5

          I run through a Runtime Error ! I'm trying to fix it with your advice ! I believe the

          table->clear()
          

          method doesn't exist in TableMethod btw ;) Can you use

          table->removeRows()
          

          it if the table is empty ?

          J 1 Reply Last reply 3 Oct 2017, 13:01
          0
          • T theo_ld
            3 Oct 2017, 12:56

            I run through a Runtime Error ! I'm trying to fix it with your advice ! I believe the

            table->clear()
            

            method doesn't exist in TableMethod btw ;) Can you use

            table->removeRows()
            

            it if the table is empty ?

            J Offline
            J Offline
            JonB
            wrote on 3 Oct 2017, 13:01 last edited by
            #6

            @theo_ld

            So tell us the runtime error! And/or check the return result + lastError()!

            clear method: what is your TableModel derived from?

            1 Reply Last reply
            0
            • T Offline
              T Offline
              theo_ld
              wrote on 3 Oct 2017, 13:08 last edited by theo_ld 10 Mar 2017, 13:13
              #7

              @JNBarchan

              My TableModel comes from QAbstractTableModel.
              lastError() works only for SQL Databases right ? Which object is it stored in ?
              Can't check the return of the function because I get a runtime error.

              Here is the console output

              Debugging starts
              ASSERT: "last >= first" in file itemmodels\qabstractitemmodel.cpp, line 2743
              Debugging has finished

              J 1 Reply Last reply 3 Oct 2017, 13:52
              0
              • T theo_ld
                3 Oct 2017, 13:08

                @JNBarchan

                My TableModel comes from QAbstractTableModel.
                lastError() works only for SQL Databases right ? Which object is it stored in ?
                Can't check the return of the function because I get a runtime error.

                Here is the console output

                Debugging starts
                ASSERT: "last >= first" in file itemmodels\qabstractitemmodel.cpp, line 2743
                Debugging has finished

                J Offline
                J Offline
                JonB
                wrote on 3 Oct 2017, 13:52 last edited by JonB 10 Mar 2017, 13:57
                #8

                @theo_ld
                Yeah, I had assumed QSqlTableModel....

                ASSERT: "last >= first" in file itemmodels\qabstractitemmodel.cpp, line 2743

                I would guess this is telling you that your start row number + number of rows >= last row in table.

                So: look at value of table->rowCount(QModelIndex()). Is it 0? In which case, if there are 0 rows, no, you cannot delete any rows from an empty table, even if you specify a count of 0 rows to delete. At a guess!

                P.S.
                Also, QAbstractTableModel requires you to subclass (TableModel), and unless that has implemented removeRows() is does nothing? You sure the example which did work did not use removeRow() (note the spelling)?

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  theo_ld
                  wrote on 3 Oct 2017, 13:56 last edited by theo_ld 10 Mar 2017, 13:57
                  #9

                  @JNBarchan You might be right, so I added a condition and it doesn't runtime anymore.

                  Although, my user isn't visible at all in the graphical interface -_-.
                  Trying to fix this problem now :p

                  J 1 Reply Last reply 3 Oct 2017, 13:59
                  0
                  • T theo_ld
                    3 Oct 2017, 13:56

                    @JNBarchan You might be right, so I added a condition and it doesn't runtime anymore.

                    Although, my user isn't visible at all in the graphical interface -_-.
                    Trying to fix this problem now :p

                    J Offline
                    J Offline
                    JonB
                    wrote on 3 Oct 2017, 13:59 last edited by
                    #10

                    @theo_ld said in Removing rows from TableModel:

                    @JNBarchan You might be right, so I added a condition and it doesn't runtime anymore.

                    In that case, I'd suggest I was right... ;-)

                    T 1 Reply Last reply 3 Oct 2017, 14:07
                    0
                    • J JonB
                      3 Oct 2017, 13:59

                      @theo_ld said in Removing rows from TableModel:

                      @JNBarchan You might be right, so I added a condition and it doesn't runtime anymore.

                      In that case, I'd suggest I was right... ;-)

                      T Offline
                      T Offline
                      theo_ld
                      wrote on 3 Oct 2017, 14:07 last edited by
                      #11
                      This post is deleted!
                      1 Reply Last reply
                      0

                      11/11

                      3 Oct 2017, 14:07

                      • Login

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