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. How to update QAbstractTableModel data

How to update QAbstractTableModel data

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 339 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.
  • I Offline
    I Offline
    IknowQT
    wrote on last edited by
    #1
    for (int k = 0; k < this->m_pKineticsInfo->GetTimes().count(); k++)
    		{
    			int nIndex = 0;
    
    			for (int i = abs(m_pDataModel->columnCount() - m_pKineticsInfo->GetCellCount()); i < m_pDataModel->columnCount(); i++)
    			{
    				QList<qreal> temp;
    
    				qreal qRan1 = QRandomGenerator::global()->bounded(0, 10);
    				qreal qRan2 = QRandomGenerator::global()->generateDouble();
    				temp.append(qRan1 + qRan2);
    				
    				m_pDataModel->AppendData(temp, i);
    				
    				lstSummary[nIndex++].AppendData(qRan1 + qRan2, this->m_pKineticsInfo->GetTimes()[k], m_pKineticsInfo->StringtoEnumUnit());
    			}
    
    			AddChartSeries(m_pDataModel);
    		}
    
    
    void usrTableModel::AppendData(QList<qreal> data, int nIndex)
    {
    	auto EmptyIndex = [=]()->int
    	{
    		for (int i = 0; i < m_lstData.count(); i++)
    		{
    			if (m_lstData[i].second.count() == 0)
    				return i;
    		}
    	};
    
    	m_lstData[nIndex].second.append(data);
    
    	// [데이터 index 재 할당]
    	QModelIndex index = createIndex(m_lstData.at(0).second.count(), m_lstData.count());
    	emit dataChanged(index, index);
    
    	emit UserDefineAppendData();
    }
    

    When data is updated in a class that inherits QAbstractTableModel, the update is not immediately reflected on the UI.

    It is updated when you move the mouse over the table or when you put the table back on the focus somewhere else.

    How do I update a table?

    JonBJ 1 Reply Last reply
    0
    • I IknowQT
      for (int k = 0; k < this->m_pKineticsInfo->GetTimes().count(); k++)
      		{
      			int nIndex = 0;
      
      			for (int i = abs(m_pDataModel->columnCount() - m_pKineticsInfo->GetCellCount()); i < m_pDataModel->columnCount(); i++)
      			{
      				QList<qreal> temp;
      
      				qreal qRan1 = QRandomGenerator::global()->bounded(0, 10);
      				qreal qRan2 = QRandomGenerator::global()->generateDouble();
      				temp.append(qRan1 + qRan2);
      				
      				m_pDataModel->AppendData(temp, i);
      				
      				lstSummary[nIndex++].AppendData(qRan1 + qRan2, this->m_pKineticsInfo->GetTimes()[k], m_pKineticsInfo->StringtoEnumUnit());
      			}
      
      			AddChartSeries(m_pDataModel);
      		}
      
      
      void usrTableModel::AppendData(QList<qreal> data, int nIndex)
      {
      	auto EmptyIndex = [=]()->int
      	{
      		for (int i = 0; i < m_lstData.count(); i++)
      		{
      			if (m_lstData[i].second.count() == 0)
      				return i;
      		}
      	};
      
      	m_lstData[nIndex].second.append(data);
      
      	// [데이터 index 재 할당]
      	QModelIndex index = createIndex(m_lstData.at(0).second.count(), m_lstData.count());
      	emit dataChanged(index, index);
      
      	emit UserDefineAppendData();
      }
      

      When data is updated in a class that inherits QAbstractTableModel, the update is not immediately reflected on the UI.

      It is updated when you move the mouse over the table or when you put the table back on the focus somewhere else.

      How do I update a table?

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

      @IknowQT
      It certainly should update without needing a refresh.

      At a guess from your code: you emit dataChanged(), which is what is required if you alter existing data in a table. However I see a lot of appending going on. If you are adding/appending/inserting new rows of data rather than just altering existing ones you must use insertRows() and call begin/endInsertRows() from it, all as per the Subclassing topic. Have you read that, isn't that related to whatever your code does?

      1 Reply Last reply
      2

      • Login

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