Results 1 to 7 of 7

Thread: QTreeWidget and QProgressDialog?

  1. #1
    Join Date
    Dec 2009
    Posts
    12
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTreeWidget and QProgressDialog?

    Hello,

    I am writing an app in QT4.5 and the application is dialog based. The purpose of the app is to load in an error file, and parse the information to the user using a textview, which displays the end result in a html formatted view. The user also has push buttons to allow the error file to be exported as text, (it is imported as a bin file...), exported as a .csv formatted file and to allow the user to view the time stamps when all of the errors occured. My problem is with the timestamp part of the application.

    I am using a QTreeWidget with QTreeWidgetItem which is called when the user presses the timestamps button. This will open the tree view in its own window, via a call to treeWidget->show(). With smaller files, everything works quite well, but, with larger files, say, 3 Mb in size, the treeWidget takes about 20 seconds before the formatted data is shown to the user. If your patient, not a problem, but I need some way of indicating to the user that the process is in fact occuring. I tried using a QProgressDialog as shown below, but the dialog is never shown to the user, and the treeWidget is not shown either until it has finished parsing the data.

    How my tree widgets and progress dialog are called:

    Qt Code:
    1. QTreeWidget *treeWidget = new QTreeWidget();
    2. treeWidget->setMinimumSize(650, 400); // int width, int height
    3. treeWidget->setColumnCount(3);
    4. treeWidget->setAlternatingRowColors(true);
    5.  
    6. QStringList headerLabels;
    7. headerLabels << "System Error Messages " << "Time Stamp: HH:MM:SS" << "Parameter";
    8. treeWidget->setHeaderLabels(headerLabels);
    9. treeWidget->resizeColumnToContents(1);
    10. treeWidget->setColumnWidth(0, 325);
    11. treeWidget->setWindowTitle(tr("Error Time Stamps"));
    12. treeWidget->setWindowIcon(QIcon(":/images/My.ico"));
    13.  
    14. QProgressDialog *infProg = new QProgressDialog("Parsing Time Records...",0,0,0,this);
    15. infProg->setRange(0,0);
    16. infProg->setWindowModality(Qt::WindowModal);
    17. QApplication::processEvents();
    18.  
    19. .... more code...
    20. // and this is how the widget is displayed
    21.  
    22. infProg->setAutoClose(true);
    23.  
    24. treeWidget->show();
    To copy to clipboard, switch view to plain text mode 

    My question is, how would I show the progress dialog while the tree view is doing its thing in the background??

    Thanks!

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget and QProgressDialog?

    Where is the code that takes 30 sec to process ? Need to see how you are processing it.

  3. #3
    Join Date
    Dec 2009
    Posts
    12
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget and QProgressDialog?

    Here is th code:

    This section creates the main treeWidget....

    Qt Code:
    1. QTreeWidget *treeWidget = new QTreeWidget();
    2. treeWidget->setMinimumSize(650, 400); // int width, int height
    3. treeWidget->setColumnCount(3);
    4. treeWidget->setAlternatingRowColors(true);
    5.  
    6. QStringList headerLabels;
    7. headerLabels << "System Error Messages " << "Time Stamp: HH:MM:SS" << "Parameter";
    8. treeWidget->setHeaderLabels(headerLabels);
    9. treeWidget->resizeColumnToContents(1);
    10. treeWidget->setColumnWidth(0, 325);
    11. treeWidget->setWindowTitle(tr("Error Time Stamps"));
    12. treeWidget->setWindowIcon(QIcon(":/images/My.ico"));
    To copy to clipboard, switch view to plain text mode 

    This section parses out the error messages. Note that I have about 20 of these, similar in nature, but are used to parse out device specific error codes.

    Qt Code:
    1. QTreeWidgetItem *tmuRoot = new QTreeWidgetItem(treeWidget); // TMU Errors - parent
    2. tmuRoot->setText(0, tr("TMU Errors"));
    3. treeWidget->addTopLevelItem(tmuRoot);
    4.  
    5. for(int i = 0; i<error.size();++i)
    6. {
    7. QTreeWidgetItem* infoTmu = new QTreeWidgetItem();
    8. infoTmu->setIcon(0, QIcon(":/images/12-em-cross_12x12.png"));
    9. infoTmu->setText(0, error[i]);
    10. infoTmu->setText(1, time[i]);
    11. infoTmu->setToolTip(0, ttTmu[i]);
    12. infoTmu->setText(2,pTmu[i]);
    13. tmuRoot->addChild(infoTmu);
    14. }
    15.  
    16. treeWidget->show();
    To copy to clipboard, switch view to plain text mode 

    The treeWidget data is collected from an error file, which can be of any length, from as little as 256 bytes, up to 5 Mb. The error file is read into and stored inside four seperate QVectors. If the error file is small, the time stamp treeWidget is parsed rather quickly and has no issues. But if the error file is quite large, (the one I am using for testing is 3 Mb in size....) the treeWidget takes quite a bit of time to fill itself up with all the values, and then when completeted, is shown to the user. The other issue is when a parent is expanded, using the vertical scroll bar to see all the error timestamps is pretty much useless as it takes several seconds to refresh the view, but that is another issue all together.....

    One section of errors, in this case anyways, has just over 300,000 child items - and this of course is the bottleneck. This is not normally the case as most child items have maybe a dozen or less errors, but we do get the odd case of a device that has been running for 24 hours or more, generating a large amount of errors.

    My original question is how to present some indication to the user that the program is actually doing something in the background once they have clicked on the button to show the timestamps?

    Thanks!

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget and QProgressDialog?

    I guess its the for loop in line 5 that processes the items from the file.
    try putting this statement in the loop -
    qApp->processEvents();

  5. #5
    Join Date
    Dec 2009
    Posts
    12
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget and QProgressDialog?

    Quote Originally Posted by aamer4yu View Post
    I guess its the for loop in line 5 that processes the items from the file.
    try putting this statement in the loop -
    qApp->processEvents();
    I did as you suggested and the treeview did not speed up any in the initial presentation to the user, but it did increase the performance when scrolling vertically. The treeview will still take a bit while scrolling, but I no longer recieve the 'Not Responding' message when the treeview is trying to update the view - so that's a bit of an improvement....

    If I was to re-write this section, are there any class's that I should look at that would maybe speed the entire process up for the end user? Can a model/view architecture be of any benefit in parsing large amounts of data to the user or is there not really any 'clean' way of presenting such large amounts of data?

    Thanks!

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget and QProgressDialog?

    Can a model/view architecture be of any benefit in parsing large amounts of data to the user
    I guess yes.
    In fact I remember we had implemented something similar when QTreeWidget had many items. Items would be cleared and added again on new data..and this was quite inefficient.
    You can give model a try

  7. #7
    Join Date
    Dec 2009
    Posts
    12
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeWidget and QProgressDialog?

    What if I load up the treeview widget, then load the data when someone expands the '+' sign? This way, I can at least show a progress dialog while the children of the root are being populated, but the trouble I am having now is connecting to the expanded signal. This is the code I was using for the signal, but the compiler complains about no matching function call for connect.

    Qt Code:
    1. connect(&rm06Root, SIGNAL(itemExpanded(QTreeWidgetItem&)), this, SLOT(loadTree()));
    To copy to clipboard, switch view to plain text mode 

    rm06Root is declared as such, as well as the code checking for expansion and then calling the function loadTree()

    Qt Code:
    1. rm06Root = new QTreeWidgetItem(treeWidget); // RMUX Errors - parent
    2. rm06Root->setText(0, tr("Ringmux 6 Errors - Tied to DSP 2A"));
    3. treeWidget->addTopLevelItem(rm06Root);
    4. if(rmx06Err.size() != 0)
    5. rm06Root->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator);
    6.  
    7. if(rm06Root->isExpanded() == true)
    8. loadTree();
    To copy to clipboard, switch view to plain text mode 

    and i have loadTree() declared in privateSlots.....

    This is the actual error message:

    /errordialog.cpp:80: error: no matching function for call to `ErrorDialog::connect(QTreeWidgetItem**, const char*, ErrorDialog* const, const char*)'

    Thanks!

Similar Threads

  1. How to execute a QProgressDialog once
    By franco.amato in forum Newbie
    Replies: 4
    Last Post: 16th March 2010, 16:36
  2. Need help in QProgressDialog
    By santhoshv84 in forum Qt Programming
    Replies: 3
    Last Post: 12th September 2008, 18:24
  3. QProgressDialog
    By samirg in forum Qt Programming
    Replies: 5
    Last Post: 5th September 2007, 16:37
  4. qprogressDialog
    By mickey in forum Qt Programming
    Replies: 5
    Last Post: 17th July 2006, 14:16
  5. setLabel in QprogressDialog
    By mickey in forum Newbie
    Replies: 5
    Last Post: 12th July 2006, 11:19

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.