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 -
// cresultstable.h
{
Q_OBJECT
public:
private:
.... // other widgets
private slots:
void batchLoadRecords(string str, int nRow);
public slots:
void loadTable(); // This will be called on signal
};
// cresultstable.h
class CResultsTable : public QTableWidget
{
Q_OBJECT
public:
CResultsTable(QString fName, QWidget *parent = 0);
private:
QTimer *batchTimer;
.... // other widgets
private slots:
void batchLoadRecords(string str, int nRow);
public slots:
void loadTable(); // This will be called on signal
};
To copy to clipboard, switch view to plain text mode
This is how I'm calling timer, timeout() to process data -
// cresultstable.cpp
{
... // other initializations
...
batchTimer = new QTimer(this);
connect(batchTimer, SIGNAL(timeout()), this, SLOT(batchLoadRecords(string, int)));
};
void CResultsTable::loadTable()
{
XMLParser *xmlParse;
xmlParse= new XMLParser();
xmlParse->Parse();
std::vector<std::string> info = xmlParse->GetInfo(); // info contains the data of parsed XML document
int numOfItems = info.size();
setRowCount(numOfItems);
batchTimer->start(); // Starting the timer here;
// Giving timeout of 0 because Qt doc says : "QTimer with a timeout of 0 will time out as soon as all the events
//in the window system's event queue have been processed. This can be used to do heavy work while
//providing a snappy user interface"
for(it = info.begin(); it != info.end(); it++)
{
std::string str = *it;
// Here I'm trying to load
batchLoadRecords(str, nRow); // Put a break-point here but it's not stopping
nRow++;
}
batchTimer->stop();
emit sig_LoadComplete();
delete xmlParse;
// cresultstable.cpp
CResultsTable::CResultsTable(QString fName, QWidget *parent) :
QTableWidget(parent)
{
... // other initializations
...
batchTimer = new QTimer(this);
connect(batchTimer, SIGNAL(timeout()), this, SLOT(batchLoadRecords(string, int)));
};
void CResultsTable::loadTable()
{
XMLParser *xmlParse;
xmlParse= new XMLParser();
xmlParse->Parse();
std::vector<std::string> info = xmlParse->GetInfo(); // info contains the data of parsed XML document
int numOfItems = info.size();
setRowCount(numOfItems);
batchTimer->start(); // Starting the timer here;
// Giving timeout of 0 because Qt doc says : "QTimer with a timeout of 0 will time out as soon as all the events
//in the window system's event queue have been processed. This can be used to do heavy work while
//providing a snappy user interface"
for(it = info.begin(); it != info.end(); it++)
{
std::string str = *it;
// Here I'm trying to load
batchLoadRecords(str, nRow); // Put a break-point here but it's not stopping
nRow++;
}
batchTimer->stop();
emit sig_LoadComplete();
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.
Bookmarks