PDA

View Full Version : QSortFilterProxyModel and QTableView problem.



Thule
10th May 2013, 08:35
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:

m_pcanTableProxyModel = new QSortFilterProxyModel(this);
ui->canTableView->setModel(m_pcanTableProxyModel);
m_pcanTableProxyModel->setSourceModel(m_pcanTableModel);

The other relevant piece of code I can think of is the data function of my model class:


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.getBroadcastStri ng(m_pcanMessageHandler->getMessage(index.row()).getCfc()));
}
else
{
return QString::fromStdString(m_cfcTable.getPeerToPeerStr ing(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;
}

Anyone able to help me with this? It's driving me slightly mad.

Santosh Reddy
10th May 2013, 09:57
Where is stack pointer when the program gets locked up / unresponsive. Try to stop the debugger and see where it is stuck !

Thule
12th May 2013, 15:49
Where is stack pointer when the program gets locked up / unresponsive. Try to stop the debugger and see where it is stuck !

I tried to debug the application but it seems it isn't really locked up, it still continues to collect data. It seems it just doesn't have the time to update the user interface.

Looks like I will just have to find another way to do this without QSortFilterProxyModel since it seems to be too slow for the amount of data the program needs to collect and show.