PDA

View Full Version : QTableWidget not updating



Dan203
11th February 2021, 02:02
I have a QTableWidget that is loaded with file info from QDir loop. I also have a QFileSystemWatcher that will call an update function if one of the files changes. It basically just reads the file info again and updates the rows. I've run into a weird issue where if I update one of the files manually in explorer the code to update the table is called from the watcher but the display doesn't actually update. However if I call the exact same function from a button it updates instantly.

I'm updating the info using calls like this....

QTableWidgetItem *pStatusItem = ui.fileList->item(row, 0);
pStatusItem->setText(sStatus);

I've tried adding ui.fileList.update() and ui.fileList.repaint() after the update, but neither works.

Another oddity is if I add a breakpoint to the code then as soon as I release the break it updates. But without the break it doesn't update.

Does anyone have any idea what's causing this?

I'm using widgets 5.15.2

Added after 7 minutes:

OK, never mind. Turns out this is some sort of timing issue. The watch event is being called so quickly that the file isn't ready to be opened so that's failing to get the info to update the list. It's working from the button and with the breakpoint because that little delay between editing the file and triggering those is enough to free up the file.