Results 1 to 3 of 3

Thread: Loading QTableWidget using QTimer like batch processing, but application holds

  1. #1
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    248
    Thanks
    91
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Loading QTableWidget using QTimer like batch processing, but application holds

    I'm parsing a XML file (size varies between 500K & 90 M) and the output of parse is a QStringList. Each index in the stringlist is split based on a seperator & the data is loaded into the table.
    So when I try to load the data into table, the application doesn't respond till the loading is complete. So I decided to do the processing in QTimer. But still the application behaves the same way while the table gets loaded with data. I tried to debug this, but the debugger isn't stopping at the break-point.

    This is how I've done -
    Qt Code:
    1. // cresultstable.h
    2. class CResultsTable : public QTableWidget
    3. {
    4. Q_OBJECT
    5. public:
    6. CResultsTable(QString fName, QWidget *parent = 0);
    7.  
    8. private:
    9. QTimer *batchTimer;
    10.  
    11. .... // other widgets
    12.  
    13. private slots:
    14. void batchLoadRecords(string str, int nRow);
    15.  
    16. public slots:
    17. void loadTable(); // This will be called on signal
    18. };
    To copy to clipboard, switch view to plain text mode 

    This is how I'm calling timer, timeout() to process data -
    Qt Code:
    1. // cresultstable.cpp
    2. CResultsTable::CResultsTable(QString fName, QWidget *parent) :
    3. QTableWidget(parent)
    4. {
    5. ... // other initializations
    6. ...
    7.  
    8. batchTimer = new QTimer(this);
    9. connect(batchTimer, SIGNAL(timeout()), this, SLOT(batchLoadRecords(string, int)));
    10. };
    11.  
    12. void CResultsTable::loadTable()
    13. {
    14. XMLParser *xmlParse;
    15. xmlParse= new XMLParser();
    16.  
    17. xmlParse->Parse();
    18. std::vector<std::string> info = xmlParse->GetInfo(); // info contains the data of parsed XML document
    19.  
    20. int numOfItems = info.size();
    21. setRowCount(numOfItems);
    22. batchTimer->start(); // Starting the timer here;
    23. // Giving timeout of 0 because Qt doc says : "QTimer with a timeout of 0 will time out as soon as all the events
    24. //in the window system's event queue have been processed. This can be used to do heavy work while
    25. //providing a snappy user interface"
    26.  
    27.  
    28. for(it = info.begin(); it != info.end(); it++)
    29. {
    30. std::string str = *it;
    31. // Here I'm trying to load
    32. batchLoadRecords(str, nRow); // Put a break-point here but it's not stopping
    33. nRow++;
    34. }
    35. batchTimer->stop();
    36. emit sig_LoadComplete();
    37. delete xmlParse;
    To copy to clipboard, switch view to plain text mode 

    How do I make the application to behave normally without holding the application event, even while loading data ? Kindly help me with this.
    Thank you.
    Last edited by rawfool; 24th June 2013 at 14:25.

  2. #2
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    248
    Thanks
    91
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Loading QTableWidget using QTimer like batch processing, but application holds

    I found a mistake in my code that I was calling batch function again in loop apart from timeout's SLOT. So, I modified my approach, but now the application is crashing.

    Qt Code:
    1. // cresultstable.h
    2. class CResultsTable : public QTableWidget
    3. {
    4. Q_OBJECT
    5. public:
    6. CResultsTable(QString fName, QWidget *parent = 0);
    7.  
    8. private:
    9. QTimer *batchTimer;
    10. std::vector<std::string>::iterator it;
    11. std::vector<std::string>::iterator endOfFile;
    12. int rowIterator;
    13.  
    14. .... // other widgets
    15.  
    16. private slots:
    17. void batchLoadRecords();
    18.  
    19. public slots:
    20. void loadTable(); // This will be called on signal
    21. };
    To copy to clipboard, switch view to plain text mode 

    Now I'm not using loop to iterate for each index of the string vector. Instead, I'm calling the batchLoadRecords() in timer's timeout slot only.
    Qt Code:
    1. // cresultstable.cpp
    2. CResultsTable::CResultsTable(QString fName, QWidget *parent) :
    3. QTableWidget(parent)
    4. {
    5. ... // other initializations
    6. ...
    7.  
    8. batchTimer = new QTimer(this);
    9. connect(batchTimer, SIGNAL(timeout()), this, SLOT(batchLoadRecords()));
    10. };
    11.  
    12. void CResultsTable::loadTable()
    13. {
    14. XMLParser *xmlParse;
    15. xmlParse= new XMLParser();
    16.  
    17. xmlParse->Parse();
    18. std::vector<std::string> info = xmlParse->GetInfo(); // info contains the data of parsed XML document
    19.  
    20. int numOfItems = info.size();
    21. setRowCount(numOfItems);
    22.  
    23. rowIterator = 0;
    24. it = info.begin();
    25. endOfFile = info.end();
    26.  
    27. batchTimer->start(); // Starting the timer here;
    28.  
    29. delete resultParse;
    30. resultParse = NULL;
    31. }
    32.  
    33. void CResultsTable::batchLoadRecords()
    34. {
    35. int temp = 0;
    36.  
    37. if(it == endOfFile)
    38. {
    39. batchTimer->stop();
    40. emit loadComplete();
    41. return;
    42. }
    43. std::string str = *it; // Break-point here
    44.  
    45. // --------- vv
    46. // Adding the data into table rows here
    47. // --------- ^^
    48.  
    49. it++;
    50. rowNumber++;
    51. }
    To copy to clipboard, switch view to plain text mode 

    I put break-point, but the application crashes and shows some dissembler code.
    The stack points at 0
    Qt Code:
    1. 0 RaiseException KERNELBASE 0x75a1812f
    2. 1 CxxThrowException MSVCR100 0x6ee8872d
    3. 2 fcloseall MSVCR100 0x6ee9f30f
    4. 3 com_ximpleware::VTDNav::getXPathStringVal MyApp 0xfb1c88
    5. 4 com_ximpleware::VTDNav::getXPathStringVal MyApp 0xfb1f7e
    6. 5 com_ximpleware::VTDNav::getXPathStringVal MyApp 0xfc3e6a
    To copy to clipboard, switch view to plain text mode 
    Last edited by rawfool; 25th June 2013 at 07:25.

  3. #3
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    248
    Thanks
    91
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Loading QTableWidget using QTimer like batch processing, but application holds

    It's solved. I had to make my std::vector<std::string> info as member variable, so that the data in that is not lost after the traverse of the function.
    Thank you.

Similar Threads

  1. Slow loading of data into QTableWidget
    By KenJustKen in forum Qt Programming
    Replies: 5
    Last Post: 11th April 2012, 15:50
  2. Problem loading multiple GIF images in qtablewidget.
    By sanket.mehta in forum Qt Programming
    Replies: 2
    Last Post: 13th September 2010, 10:31
  3. File Processing Application Quirk
    By sgrant327 in forum Qt Programming
    Replies: 1
    Last Post: 9th September 2010, 18:55
  4. Replies: 3
    Last Post: 1st October 2009, 23:19
  5. QTimer - too many in application??
    By db in forum Newbie
    Replies: 4
    Last Post: 31st March 2008, 15:12

Tags for this Thread

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.