PDA

View Full Version : Best approach to have a Table to update values



arunvv
21st February 2008, 19:51
Hi All,

I want to create a table (23 rows, 6 colums) which should update some values and it should be dynamic for rows.
I want the best approach to do this, which should consume less CPU load, the items are just to display values, sholud not be editable etc, table is used to just display values and keep updating every second.

I Used QTableWidget for creating table but it seems taking a lot of CPU load nearly 90%

Can you help me in creating table with best approach?

Thanks & Regards,
Arun

jacek
21st February 2008, 21:26
How do you read the data?

arunvv
21st February 2008, 21:39
Hi Jacek,

Here is the snippet of code , creating a table and reading data. Correct me if anything wrong in it.

function(eguiMsgData *eguiTxMsg)
{
tableWidget_TxPathHistory->setRowCount(totalpathnum);
tableWidget_TxPathHistory->setColumnCount(6);
tableWidget_TxPathHistory->setHorizontalHeaderLabels(QStringList() << tr("delta1")
<< tr("delta2") << tr("delta3") << tr("delta4") << tr("PosErr") << tr("Valid"));
tableWidget_TxPathHistory->resizeColumnsToContents();

for(column = 0; column < 6; column++)
{
for (row = 0; row < ; row++)
{
QTableWidgetItem *Txdelta1 = new QTableWidgetItem();
Txdelta1->setFlags(~Qt::ItemIsSelectable | ~Qt::ItemIsEnabled);
Txdelta1->setFlags(Txdelta1->flags() & ~Qt::ItemIsEditable);
Txdelta1->setText(Q_TxPathHistorydelta1.setNum(eguiTxMsg->pathHistoryList[row].delta1,'g',6));
tableWidget_TxPathHistory->setItem(row, column, Txdelta1);

QTableWidgetItem *Txdelta2 = new QTableWidgetItem();
Txdelta2->setFlags(~Qt::ItemIsSelectable | ~ Qt::ItemIsEnabled);
Txdelta2->setFlags(Txdelta2->flags() &~ Qt::ItemIsEditable);
Txdelta2->setText(Q_TxPathHistorydelta2.setNum(eguiTxMsg->pathHistoryList[row].delta2,'g',6));
tableWidget_TxPathHistory->setItem(row, column, Txdelta2);
.....
.....
(Similarly for other 4 columns.)
}
}
tableWidget_TxPathHistory->setEditTriggers(QTableWidget::NoEditTriggers);
}


Thanks & Regards,
Arun

jacek
21st February 2008, 21:50
And you do that every second?

arunvv
21st February 2008, 22:03
Yes I update values every second because I am calling this function from a QTimer routine.

A code snippet given below.


void MainWindow::startEGUIDataTimer()
{
eguiDisplayTimer = new QTimer();
connect(eguiDisplayTimer, SIGNAL(timeout()), this, SLOT(printEGUI()));
eguiDisplayTimer->start(1000);
}

void MainWindow::printEGUI()
{
....
.... //functions to print some other values for other tab widgets
function() //table function
}

I modified the code in such a way that what ever tab is active based on that active tab it prints its values. To print values for other tabs, I am using QLabels because it is just to display. But only for one tab I require table to display a list of values. So only for this table tab the CPU load is very high(varies from 60-90%) and for other tabs it is it is quite low.(2-7%)

Thanks & Regards
Arun.

jacek
21st February 2008, 22:17
Yes I update values every second because I am calling this function from a QTimer routine.
I'm sure you will save some CPU time if you just update the values in QTableWidgetItems instead of recreating the table.

arunvv
22nd February 2008, 01:01
I changed the code , so that I can update the items only for a table instead of creating and updating entire table. But still no luck.

I made all the items as non editable, no triggers, no tab navigation etc...
Still consuming more CPU load.

Any suggestions are welcome?

Thanks & Regards,
Arun.

jacek
25th February 2008, 12:30
I changed the code , so that I can update the items only for a table instead of creating and updating entire table. But still no luck.

I made all the items as non editable, no triggers, no tab navigation etc...
Still consuming more CPU load.
How many times do you invoke MainWindow::startEGUIDataTimer()?

Have you tried to use a profiler?

wysota
25th February 2008, 17:00
I suggest implementing a real model and updating all values at once. Currently dataChanged() signal is emited 23*6 times (and then the view refreshes itself) and it's only needed once. Just make sure you don't use QStandardItemModel or it will not work.