Hi there,
I am developing a program that gets data from a CAN bus interface and presents the data in a QTableView.
The program receives about 600 messages per second, sometimes more and it all works beautifully. QTableView is easily able to keep up with all the new rows being added.
Now to my problem.
I have encountered a problem when trying to use QSortFilterProxyModel to filter the data presented to the user.
At first i tried to filter on the value of a column and it worked for a very short while, about 2 seconds before the program just locked up.
After that i tried to just connect the proxymodel to the model and the view without doing any filtering. Now the program works for about ten seconds before slowing to a crawl and then locking up once again.
I connect the proxy model like this:
ui->canTableView->setModel(m_pcanTableProxyModel);
m_pcanTableProxyModel->setSourceModel(m_pcanTableModel);
m_pcanTableProxyModel = new QSortFilterProxyModel(this);
ui->canTableView->setModel(m_pcanTableProxyModel);
m_pcanTableProxyModel->setSourceModel(m_pcanTableModel);
To copy to clipboard, switch view to plain text mode
The other relevant piece of code I can think of is the data function of my model class:
{
if (role != Qt::DisplayRole)
{
}
switch (index.column())
{
case CanMessage::Time:
if (m_timeFlag == 0)
{
return QString::number(m_pcanMessageHandler
->getMessage
(index.
row()).
getSeconds());
}
else // relative time
{
return m_pcanMessageHandler->getRelativeTime(index.row());
}
break;
case CanMessage::Status:
return m_pcanMessageHandler->getMessage(index.row()).getStatus();
break;
case CanMessage::CanID:
if (m_hexIdFlag == 1)
{
return QString::number(m_pcanMessageHandler
->getMessage
(index.
row()).
getId(),
16);
}
else
{
return m_pcanMessageHandler->getMessage(index.row()).getId();
}
break;
case CanMessage::CFC:
if (m_cfcFlag == 1)
{
if (index.model()->data(index.model()->index(index.row(), 4)) == 0)
{
return QString::fromStdString(m_cfcTable.
getBroadcastString(m_pcanMessageHandler
->getMessage
(index.
row()).
getCfc()));
}
else
{
return QString::fromStdString(m_cfcTable.
getPeerToPeerString(m_pcanMessageHandler
->getMessage
(index.
row()).
getCfc()));
}
}
else
{
return m_pcanMessageHandler->getMessage(index.row()).getCfc();
}
break;
case CanMessage::Module:
return m_pcanMessageHandler->getMessage(index.row()).getModule();
break;
case CanMessage::Length:
return m_pcanMessageHandler->getMessage(index.row()).getLength();
break;
case CanMessage::Data:
if (m_hexDataFlag == 1)
{
return QString::fromStdString(m_pcanMessageHandler
->getMessage
(index.
row()).
getDataString(true));
}
else
{
return QString::fromStdString(m_pcanMessageHandler
->getMessage
(index.
row()).
getDataString(false));
}
break;
}
}
QVariant CanTableModel::data(const QModelIndex &index, int role) const
{
if (role != Qt::DisplayRole)
{
return QVariant::Invalid;
}
switch (index.column())
{
case CanMessage::Time:
if (m_timeFlag == 0)
{
return QString::number(m_pcanMessageHandler->getMessage(index.row()).getSeconds());
}
else // relative time
{
return m_pcanMessageHandler->getRelativeTime(index.row());
}
break;
case CanMessage::Status:
return m_pcanMessageHandler->getMessage(index.row()).getStatus();
break;
case CanMessage::CanID:
if (m_hexIdFlag == 1)
{
return QString::number(m_pcanMessageHandler->getMessage(index.row()).getId(),16);
}
else
{
return m_pcanMessageHandler->getMessage(index.row()).getId();
}
break;
case CanMessage::CFC:
if (m_cfcFlag == 1)
{
if (index.model()->data(index.model()->index(index.row(), 4)) == 0)
{
return QString::fromStdString(m_cfcTable.getBroadcastString(m_pcanMessageHandler->getMessage(index.row()).getCfc()));
}
else
{
return QString::fromStdString(m_cfcTable.getPeerToPeerString(m_pcanMessageHandler->getMessage(index.row()).getCfc()));
}
}
else
{
return m_pcanMessageHandler->getMessage(index.row()).getCfc();
}
break;
case CanMessage::Module:
return m_pcanMessageHandler->getMessage(index.row()).getModule();
break;
case CanMessage::Length:
return m_pcanMessageHandler->getMessage(index.row()).getLength();
break;
case CanMessage::Data:
if (m_hexDataFlag == 1)
{
return QString::fromStdString(m_pcanMessageHandler->getMessage(index.row()).getDataString(true));
}
else
{
return QString::fromStdString(m_pcanMessageHandler->getMessage(index.row()).getDataString(false));
}
break;
}
return QVariant::Invalid;
}
To copy to clipboard, switch view to plain text mode
Anyone able to help me with this? It's driving me slightly mad.
Bookmarks