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. beginInsertRows()
Forum Updated to NodeBB v4.3 + New Features

beginInsertRows()

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 954 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.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by
    #1

    Assume that I want to insert some rows into a table model.

    The data for the model is held as:

    std::vector<ListBitMap> mydata;
    

    If I have 10 items that I might add can I use:

    model.beginInsertRows(QModelIndex(), mydata.size(), mydata.size()+10);
    

    and then add between 0 and 10 rows

    and then issue endInsertRows(), or do I need to add EXACTLY 10 rows?

    Thanks, David

    JonBJ 1 Reply Last reply
    0
    • PerdrixP Perdrix

      Assume that I want to insert some rows into a table model.

      The data for the model is held as:

      std::vector<ListBitMap> mydata;
      

      If I have 10 items that I might add can I use:

      model.beginInsertRows(QModelIndex(), mydata.size(), mydata.size()+10);
      

      and then add between 0 and 10 rows

      and then issue endInsertRows(), or do I need to add EXACTLY 10 rows?

      Thanks, David

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

      @Perdrix
      You must tell insertRows() how many rows you are inserting, not lie to it! :)

      1 Reply Last reply
      0
      • PerdrixP Offline
        PerdrixP Offline
        Perdrix
        wrote on last edited by
        #3

        Well that's a great shame, as I don't know a-priori how many items in the QStringList that I am iterating will actually meet the criteria for being added to table model.

        Need to contemplate how best to handle this.
        D.

        JonBJ 1 Reply Last reply
        0
        • PerdrixP Perdrix

          Well that's a great shame, as I don't know a-priori how many items in the QStringList that I am iterating will actually meet the criteria for being added to table model.

          Need to contemplate how best to handle this.
          D.

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

          @Perdrix
          :) Then don't call beginInsertRows() at the start/till you do. Do your processing first to find out in one pass, then do the adding of the rows in a second pass. Or put them into your mydata and call beginInsertRows() only after you have added them all into your data to let then model know then (I think that's safe for simple case). Or, just call beginInsertRows() each time you come up with one row which needs adding. Not sure you'd notice the difference, I think the multiple-rows call is just an optimization to e.g. help the viewer know it could allow for a bunch of updates in one go, it's not mandatory and probably irrelevant unless there are a "large" number of total rows/rows to insert.

          1 Reply Last reply
          1
          • PerdrixP Offline
            PerdrixP Offline
            Perdrix
            wrote on last edited by
            #5

            OK thank you...

            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