TextEditor and insertTextAtCursor()


#1

I use a TextEditor as a console to print out information about what the application is doing. My problem is, I do it in a loop, and the texts I insert only appear after it’s done with the whole loop. I would like it to print each messages in every round, because I am uploading files to a server, and when I upload many files, you cannot decide whether the app has frozen or is working, because it won’t show any info about it, but prints the whole bunch of messages after it’s done. I tried to call repaint() after I inserted the text, but didn’t help. Somehow I should make it stop in each loops until it prints the message, then continue but I don’t know how.
Any ideas?


#2

If you just block the event thread and sit there doing some work, then of course the app will freeze up - it can’t deliver any events until your routine has finished! Sounds like someone needs to learn about threads!


#3

[quote=“rolanddd”]I use a TextEditor as a console to print out information about what the application is doing. My problem is, I do it in a loop, and the texts I insert only appear after it’s done with the whole loop. I would like it to print each messages in every round, because I am uploading files to a server, and when I upload many files, you cannot decide whether the app has frozen or is working, because it won’t show any info about it, but prints the whole bunch of messages after it’s done. I tried to call repaint() after I inserted the text, but didn’t help. Somehow I should make it stop in each loops until it prints the message, then continue but I don’t know how.
Any ideas?[/quote]
Why don’t you create a worker thread to upload the file and from that worker thread send messages to update the editor.


#4

well Jules is right because I should learn about threads. Could you show me a simple example how to create a worker thread to do the job and send a message to the text editor?