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. QAbstractItemModel::rowsInserted notworking
Forum Updated to NodeBB v4.3 + New Features

QAbstractItemModel::rowsInserted notworking

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 497 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.
  • I Offline
    I Offline
    IknowQT
    wrote on last edited by
    #1
    	QList<QStandardItem*> items;
    	{
    		// [Sample Name]
    		{
    			items.append(new usrStandardItem(strName));			
    		}
    
    		// [Conc]
    		items.append(new usrStandardItem(fConc));
    
    		// [Abs]
    		items.append(new usrStandardItem(fAbs));
    
    		// [Factor]
    		items.append(new usrStandardItem(this->m_pQttInfo->fFactor));
    
    		// [Cell]
    		items.append(new usrStandardItem(strCell));
    
    		// [Time]
    		items.append(new usrStandardItem(QDateTime::currentDateTime().toString("yy-MM-dd HH:mm:ss")));
    	}
    	m_pDataModel->appendRow(items);
    
    this->connect(this->m_pDataModel, &QAbstractItemModel::rowsInserted, this->m_pDataModel, [this]
    	(const QModelIndex& index, int iStart, int iEnd) -> void 
    		{
    			qDebug() << "QAbstractItemModel::rowsInserted: " << index << iStart << iEnd;
    			this->ui.tableWidget->scrollTo(m_pDataModel->index(iStart, 0), QAbstractItemView::PositionAtBottom);
    		});
    

    It doesn't mean it can't, but it doesn't go down to the very end. And if you take the index value of the (const QModelIndex& index, int iStart, int iEnd) parameter, QModelIndex(-1,-1,0x0,QObject(0x0)) comes out.

    When I do a data insertrow, I want to move to the last row.

    Christian EhrlicherC 1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      Then please provide a minimal, compilable example to reproduce your problem. Works fine in a similar situation for me. You can also set the vertical slider to max.

      I Offline
      I Offline
      IknowQT
      wrote on last edited by
      #5

      @Christian-Ehrlicher

      	this->connect(this->m_pDataModel, &QAbstractItemModel::rowsInserted, this->m_pDataModel, [this]
      	(const QModelIndex& index, int iStart, int iEnd) -> void 
      		{
      			QTimer::singleShot(0, [=]() { this->ui.tableWidget->scrollToBottom(); });
      		});
      

      Strangely, if 10 data is added, it moves to the last row up to 9, but does not move to the 10th row.
      I solved this problem with the code I posted.

      1 Reply Last reply
      0
      • I IknowQT
        	QList<QStandardItem*> items;
        	{
        		// [Sample Name]
        		{
        			items.append(new usrStandardItem(strName));			
        		}
        
        		// [Conc]
        		items.append(new usrStandardItem(fConc));
        
        		// [Abs]
        		items.append(new usrStandardItem(fAbs));
        
        		// [Factor]
        		items.append(new usrStandardItem(this->m_pQttInfo->fFactor));
        
        		// [Cell]
        		items.append(new usrStandardItem(strCell));
        
        		// [Time]
        		items.append(new usrStandardItem(QDateTime::currentDateTime().toString("yy-MM-dd HH:mm:ss")));
        	}
        	m_pDataModel->appendRow(items);
        
        this->connect(this->m_pDataModel, &QAbstractItemModel::rowsInserted, this->m_pDataModel, [this]
        	(const QModelIndex& index, int iStart, int iEnd) -> void 
        		{
        			qDebug() << "QAbstractItemModel::rowsInserted: " << index << iStart << iEnd;
        			this->ui.tableWidget->scrollTo(m_pDataModel->index(iStart, 0), QAbstractItemView::PositionAtBottom);
        		});
        

        It doesn't mean it can't, but it doesn't go down to the very end. And if you take the index value of the (const QModelIndex& index, int iStart, int iEnd) parameter, QModelIndex(-1,-1,0x0,QObject(0x0)) comes out.

        When I do a data insertrow, I want to move to the last row.

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @IknowQT said in QAbstractItemModel::rowsInserted notworking:

        QModelIndex(-1,-1,0x0,QObject(0x0)) comes out.

        Which is correct since you're adding your items to the root item.

        When I do a data insertrow, I want to move to the last row.

        Why do you use iStart then instead the rowCount() - 1 ?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        I 1 Reply Last reply
        2
        • Christian EhrlicherC Christian Ehrlicher

          @IknowQT said in QAbstractItemModel::rowsInserted notworking:

          QModelIndex(-1,-1,0x0,QObject(0x0)) comes out.

          Which is correct since you're adding your items to the root item.

          When I do a data insertrow, I want to move to the last row.

          Why do you use iStart then instead the rowCount() - 1 ?

          I Offline
          I Offline
          IknowQT
          wrote on last edited by IknowQT
          #3

          @Christian-Ehrlicher

          It's not that I haven't used it. I used row()-1, but it didn't go to the last row.

          From 9 to 8 rows work normally, but it does not move to the last row.

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by Christian Ehrlicher
            #4

            Then please provide a minimal, compilable example to reproduce your problem. Works fine in a similar situation for me. You can also set the vertical slider to max.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            I 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              Then please provide a minimal, compilable example to reproduce your problem. Works fine in a similar situation for me. You can also set the vertical slider to max.

              I Offline
              I Offline
              IknowQT
              wrote on last edited by
              #5

              @Christian-Ehrlicher

              	this->connect(this->m_pDataModel, &QAbstractItemModel::rowsInserted, this->m_pDataModel, [this]
              	(const QModelIndex& index, int iStart, int iEnd) -> void 
              		{
              			QTimer::singleShot(0, [=]() { this->ui.tableWidget->scrollToBottom(); });
              		});
              

              Strangely, if 10 data is added, it moves to the last row up to 9, but does not move to the 10th row.
              I solved this problem with the code I posted.

              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