PDA

View Full Version : QTextEdit doesn't append text



Luc4
13th June 2010, 13:31
Hi! I created I loop in which I copy files from a location to a another. When I copy one file, I inform the user of the file name. Unfortunately, it seems that if I inform the user by placing a qDebug output, the string is written correclty, if I use the method append of QTextEdit, nothing is written. I simply have this:


QString filename;
foreach (filename, list) {
// So something.
textEdit->append("Some text describing what I'm doing.");
qDebug("Some text describing what I'm doing.");
QFile file(currentDir.absoluteFilePath(fileName));
file.copy(newPath);
}

In this situation, qDebug writes the sentence in the right place, but textEdit shows nothing of what it should. Maybe the application is too busy to do anything, including writing something? Any way I can do what I need?
Thanks!

wysota
13th June 2010, 13:44
You are blocking the event loop so the widget can't update itself.
Keeping the GUI Responsive

Luc4
13th June 2010, 16:29
Thank you very much. This solved the issue.
There is only one thing I'm noticing: even if I close my QMainWindow it seems the loop is not stopped... Any idea why?
Thanks!

wysota
13th June 2010, 16:53
Why would the loop stop if you close the window?

Luc4
13th June 2010, 20:56
Right... But I also tried to call the quit() method of QApplication when I get the closeEvent of my main window, but nothing happens. Shouldn't that be sufficient?
Thanks for your help!

wysota
13th June 2010, 21:04
You won't receive a close event if you block the event loop.

Luc4
13th June 2010, 21:24
:) Seems difficult to simply close an application...
I tried with:
qApp->setQuitOnLastWindowClosed(true);
but seems this is not quitting the event loop as well... Maybe my only option is to switch to using a worker thread...

wysota
13th June 2010, 23:45
Did you read the article I pointed you to? It deals with solutions to problems such as yours.