Results 1 to 9 of 9

Thread: Best approach to have a Table to update values

  1. #1
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Best approach to have a Table to update values

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Best approach to have a Table to update values

    How do you read the data?

  3. #3
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Best approach to have a Table to update values

    Hi Jacek,

    Here is the snippet of code , creating a table and reading data. Correct me if anything wrong in it.
    Qt Code:
    1. function(eguiMsgData *eguiTxMsg)
    2. {
    3. tableWidget_TxPathHistory->setRowCount(totalpathnum);
    4. tableWidget_TxPathHistory->setColumnCount(6);
    5. tableWidget_TxPathHistory->setHorizontalHeaderLabels(QStringList() << tr("delta1")
    6. << tr("delta2") << tr("delta3") << tr("delta4") << tr("PosErr") << tr("Valid"));
    7. tableWidget_TxPathHistory->resizeColumnsToContents();
    8.  
    9. for(column = 0; column < 6; column++)
    10. {
    11. for (row = 0; row < ; row++)
    12. {
    13. Txdelta1->setFlags(~Qt::ItemIsSelectable | ~Qt::ItemIsEnabled);
    14. Txdelta1->setFlags(Txdelta1->flags() & ~Qt::ItemIsEditable);
    15. Txdelta1->setText(Q_TxPathHistorydelta1.setNum(eguiTxMsg->pathHistoryList[row].delta1,'g',6));
    16. tableWidget_TxPathHistory->setItem(row, column, Txdelta1);
    17.  
    18. Txdelta2->setFlags(~Qt::ItemIsSelectable | ~ Qt::ItemIsEnabled);
    19. Txdelta2->setFlags(Txdelta2->flags() &~ Qt::ItemIsEditable);
    20. Txdelta2->setText(Q_TxPathHistorydelta2.setNum(eguiTxMsg->pathHistoryList[row].delta2,'g',6));
    21. tableWidget_TxPathHistory->setItem(row, column, Txdelta2);
    22. .....
    23. .....
    24. (Similarly for other 4 columns.)
    25. }
    26. }
    27. tableWidget_TxPathHistory->setEditTriggers(QTableWidget::NoEditTriggers);
    28. }
    To copy to clipboard, switch view to plain text mode 

    Thanks & Regards,
    Arun
    Last edited by jacek; 21st February 2008 at 21:49. Reason: reformatted to look better

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Best approach to have a Table to update values

    And you do that every second?

  5. #5
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Best approach to have a Table to update values

    Yes I update values every second because I am calling this function from a QTimer routine.

    A code snippet given below.

    Qt Code:
    1. void MainWindow::startEGUIDataTimer()
    2. {
    3. eguiDisplayTimer = new QTimer();
    4. connect(eguiDisplayTimer, SIGNAL(timeout()), this, SLOT(printEGUI()));
    5. eguiDisplayTimer->start(1000);
    6. }
    7.  
    8. void MainWindow::printEGUI()
    9. {
    10. ....
    11. .... //functions to print some other values for other tab widgets
    12. function() //table function
    13. }
    To copy to clipboard, switch view to plain text mode 
    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.
    Last edited by jpn; 22nd February 2008 at 06:44. Reason: missing [code] tags

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Best approach to have a Table to update values

    Quote Originally Posted by arunvv View Post
    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.

  7. #7
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Best approach to have a Table to update values

    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.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Best approach to have a Table to update values

    Quote Originally Posted by arunvv View Post
    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?

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Best approach to have a Table to update values

    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.

Similar Threads

  1. Inserting Integer Values to table.
    By kenny_isles in forum Newbie
    Replies: 2
    Last Post: 22nd February 2007, 07:17
  2. Updating Table Values.
    By kenny_isles in forum Newbie
    Replies: 14
    Last Post: 13th February 2007, 11:04
  3. adding in values to table
    By therealjag in forum Qt Programming
    Replies: 2
    Last Post: 9th February 2006, 16:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.