Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. what value i need to pass to beginInsertRows() & insertRows() if i have to append only one row at the end ?
Forum Updated to NodeBB v4.3 + New Features

what value i need to pass to beginInsertRows() & insertRows() if i have to append only one row at the end ?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 917 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.
  • D Offline
    D Offline
    divaindie
    wrote on 30 Jan 2019, 11:21 last edited by
    #1

    in one of my application iam using 'QSqlRelationalTableModel' as the model for listview on QML end
    so i have overrided insertRows() ,where before actually inserting new rows iam calling beginInsertRows() function and endInsertRows() after inserting rows.

    but for some reason listview in QML is ending up with random no of delegates(i.e if i append single row to sqlite table via 'QSqlRelationalTableModel' object ,listview will show same row two times (it looks like i have appended two rows with same data values but i have appended only one ,if i check the physical DB actually only one row is appended!!!)
    i guess argument i passed to below functions are not correct !!

    beginInsertRows(QModelIndex(),totalRows,totalRows); //where totalrows=0 incase firstly there are no rows in table,it will increment by as i append
    insertRows(totalRows,1,QModelIndex());
    endInsertRows();
    

    please tell me what value i need to pass to beginInsertRows() & insertRows() if i have to append only one row at the end .

    V 1 Reply Last reply 30 Jan 2019, 11:26
    0
    • D divaindie
      30 Jan 2019, 11:21

      in one of my application iam using 'QSqlRelationalTableModel' as the model for listview on QML end
      so i have overrided insertRows() ,where before actually inserting new rows iam calling beginInsertRows() function and endInsertRows() after inserting rows.

      but for some reason listview in QML is ending up with random no of delegates(i.e if i append single row to sqlite table via 'QSqlRelationalTableModel' object ,listview will show same row two times (it looks like i have appended two rows with same data values but i have appended only one ,if i check the physical DB actually only one row is appended!!!)
      i guess argument i passed to below functions are not correct !!

      beginInsertRows(QModelIndex(),totalRows,totalRows); //where totalrows=0 incase firstly there are no rows in table,it will increment by as i append
      insertRows(totalRows,1,QModelIndex());
      endInsertRows();
      

      please tell me what value i need to pass to beginInsertRows() & insertRows() if i have to append only one row at the end .

      V Offline
      V Offline
      VRonin
      wrote on 30 Jan 2019, 11:26 last edited by
      #2

      @divaindie said in what value i need to pass to beginInsertRows() & insertRows() if i have to append only one row at the end ?:

      insertRows(totalRows,1,QModelIndex());

      That one will call begin/endInsertRows again (if not actually calling an infinite recursion). Why do you need to subclass QSqlRelationalTableModel? the default implementation of insertRows should work just fine

      "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
      2
      • D Offline
        D Offline
        divaindie
        wrote on 30 Jan 2019, 12:33 last edited by
        #3

        if i have to use "QSqlRelationalTableModel" as a model to listview in QML, i need to generate role names(that i will be generating it in my subclass) . that is the reason i created a derived class of "QSqlRelationalTableModel" !!!

        also in QT doc it is mentioned that if we override insertRows() , we must call begin & endInsertRows in our overrided function.

        V 1 Reply Last reply 30 Jan 2019, 12:36
        0
        • D divaindie
          30 Jan 2019, 12:33

          if i have to use "QSqlRelationalTableModel" as a model to listview in QML, i need to generate role names(that i will be generating it in my subclass) . that is the reason i created a derived class of "QSqlRelationalTableModel" !!!

          also in QT doc it is mentioned that if we override insertRows() , we must call begin & endInsertRows in our overrided function.

          V Offline
          V Offline
          VRonin
          wrote on 30 Jan 2019, 12:36 last edited by
          #4

          @divaindie said in what value i need to pass to beginInsertRows() & insertRows() if i have to append only one row at the end ?:

          i need to generate role names(that i will be generating it in my subclass) . that is the reason i created a derived class of "QSqlRelationalTableModel" !!!

          Makes sense

          @divaindie said in what value i need to pass to beginInsertRows() & insertRows() if i have to append only one row at the end ?:

          also in QT doc it is mentioned that if we override insertRows() , we must call begin & endInsertRows in our overrided function.

          Why are you overriding insertRows? You don't have to override every single method of the subclass

          "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
          2

          1/4

          30 Jan 2019, 11:21

          • Login

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