PDA

View Full Version : QTreeWidget row updates inside QDialog



innerhippy
18th December 2008, 16:32
Hello!

I have a problem regarding udpates to a QTreeWidget inside a QDialog.

The dialog pops up and prompts the user to select a file. This file is read and for each line I want the data to be displayed inside a QTreeWidget. So far so easy.

But, I want each row to be displayed as soon as it is read from the file, but at preset the treeWidget blocks until the whole file is read - only then is all the data displayed.

I'm sure there's an eay fix for this -but I can't for the life of me find it! I've tried various modality options, calls to QCoreApplication::processEvents(), even using threads (slght overkill) - but nothing seems to work.

Any clues anyone?

aamer4yu
19th December 2008, 06:10
How are you populating the treewidget ? can we see the code ?

innerhippy
19th December 2008, 09:34
The treeWidget is populated as ..



QTreeWidgetItem* topLevelItem = new QTreeWidgetItem (treeWidget);
treeWidget->addTopLevelItem(currItem);

for (read line from file) {
QTreeWidgetItem* item = new QTreeWidgetItem (topLevelItem);
item->setText(0, "field 1 from file")
item->setText(1, "field 2 from file")
treeWidget->scrollToItem(item);
}

spirit
19th December 2008, 09:59
you can create a thread in which you can read data from file line by line and then you can send signal with line which has been read from file to your dialog and then add this line to QTreeWidget.

aamer4yu
19th December 2008, 18:32
Try calling treewidget->update() in the for loop
Am not sure though if it wil work