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. [Solved] QAbstractTableModel rowsInserted (const QModelIndex & parent, int start, int end) signal
Forum Updated to NodeBB v4.3 + New Features

[Solved] QAbstractTableModel rowsInserted (const QModelIndex & parent, int start, int end) signal

Scheduled Pinned Locked Moved General and Desktop
18 Posts 4 Posters 12.7k 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.
  • A Offline
    A Offline
    andre
    wrote on last edited by
    #7

    [quote author="ZapB" date="1304519890"]Andre, not in the implementation no.[/quote]
    "D'oh":http://en.wikipedia.org/wiki/D'oh! !
    Of course not.

    ZabB is absolutely right.

    1 Reply Last reply
    0
    • W Offline
      W Offline
      WilliamU
      wrote on last edited by
      #8

      Hi Guys,

      The (schoolboy error of mine) with arguments in the connect(ion) now removed has solved the error, thank you but that still doesn't explain why the signal doesn't appear in the auto-completion list!

      Thank's again.

      --
      William

      Regards,

      William

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #9

        That, I think, would be an issue of Qt Creator.

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          ZapB
          wrote on last edited by
          #10

          That's a separate issue and likely related to Qt-Creator's code model. Which version of creator are you using?

          Nokia Certified Qt Specialist
          Interested in hearing about Qt related work

          1 Reply Last reply
          0
          • W Offline
            W Offline
            WilliamU
            wrote on last edited by
            #11

            To answer your question ZapB I am using v2.1.0 (Qt 4.7.1) 32 bit on Windows Vista x64

            Also now I have my signal connected I don't get notification of any rows being added!

            I have changed the code to this:
            @
            if (m_Model)
            {
            if (connect(m_Model, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(modelRowsInserted(QModelIndex, int, int))))
            {
            // Load model from file.
            if (m_Model->load("./input.xml"))
            {
            // Assign the model to the view
            ui->myModelView->setModel(m_Model);
            }
            }
            }
            @

            With my slot being:
            @
            void MainWindow::modelRowsInserted ( const QModelIndex & parent, int start, int end )
            {
            qDebug() << "Rows Added to Model" ;
            }
            @

            But I never see any output in the Application Output console even though my model correctly displays the (processed) content of the input file. In this instance I would have expected to see two lines in the output console based on the content of the file and what is correctly displayed in the View.

            --
            William

            Regards,

            William

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #12

              That might suggest that your model is not correctly implemented.

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                ZapB
                wrote on last edited by
                #13

                I agree with Andre. Do you call beginInsertRows() and endInsertRows() around the place where you actually modify your internal data structure? Can you post this piece of code please?

                Nokia Certified Qt Specialist
                Interested in hearing about Qt related work

                1 Reply Last reply
                0
                • W Offline
                  W Offline
                  WilliamU
                  wrote on last edited by
                  #14

                  Hi,

                  Well I cannot see what else I am missing as as far as I can tell I have no need to re-implement anything other than those already listed as this is a read only model. I am relying on (my assumption) that this signal will (should) get emitted (via the default implementation) when a new row is inserted.

                  --
                  William

                  Regards,

                  William

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    giesbert
                    wrote on last edited by
                    #15

                    Hi William,

                    who should add rows that emit this signal?
                    If you change the content of the model, you have to call the defined methods, like begine/end insert Rows/columns. Same for remove.
                    Without calling these, the signals will not be emitted.

                    EDIT: I assume, the content of your model is static? Or is it dynamic? if it is dynamic, the model is responsible for notifying the clients.

                    Nokia Certified Qt Specialist.
                    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                    1 Reply Last reply
                    0
                    • Z Offline
                      Z Offline
                      ZapB
                      wrote on last edited by
                      #16

                      Read-only model means read-only as far as the QAbstractItemModel's interface is concerned. ie an attached view will not allow users to edit the model. However, you are still changing the model when you load your data and so you need to call beginInsertRows() and endInsertRows() around the place where you modify your underlying data structure. It is the call to endInsertRows() that causes your missing signal to be emitted. How else would the model know what you are doing behind it's back?

                      Nokia Certified Qt Specialist
                      Interested in hearing about Qt related work

                      1 Reply Last reply
                      0
                      • W Offline
                        W Offline
                        WilliamU
                        wrote on last edited by
                        #17

                        Thanks Gerolf and ZapB, it's just got very bright in here. :-)

                        Thanks again.

                        --
                        William

                        Regards,

                        William

                        1 Reply Last reply
                        0
                        • Z Offline
                          Z Offline
                          ZapB
                          wrote on last edited by
                          #18

                          No worries. I remember the pains of learning the modelview architecture. It can be confusing. The trick is to remember that QAbstractItemModel is only an interface to your data that us used by the views. You have to nudge it it the right direction when you change your data behind it's back by calling the appropriate protected functions.

                          Good luck with the rest of your project!

                          Nokia Certified Qt Specialist
                          Interested in hearing about Qt related work

                          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