Qt: How to use QTimer to print a message to a QTextBrowser every 10 seconds?
Posted
by
Aaron McKellar
on Stack Overflow
See other posts from Stack Overflow
or by Aaron McKellar
Published on 2011-01-14T19:25:59Z
Indexed on
2011/01/14
19:53 UTC
Read the original article
Hit count: 191
Hello,
I have working at this for hours and cannot figure it out nor can I find any help online that works. Basically the gist of what I am trying to accomplish is to have a Qt GUI with a button and a QTextBrowser. When I push the button I want it to diplay a message and then keep printing this message every 10 seconds.
I figured I would use QTimer because it makes sense to have a timer to diplay the message every 10 seconds. When I originally implemented this into my buttonClicked() SLOT it caused the program to freeze. I looked online for a solution and found QApplication::processEvents().
So basically in my function I had something like this:
while(1)
{
QTimer *timer;
connect(...) //omitted parameters for this example
timer.start(10000);
ui->diplay->append("Message");
while(timer.isActive())
{
QApplication::processEvents()
}
}
I figured it would break out of the timer.isActive() while loop but it won't it simply stays in there.
So I figured this is a threading issue. So I figured out how to use QThreads but I still can't get it to work. Basically when I create a thread with a timer on it and the thread tells the timer to start, the program closes and the console says "The program has unexpectedly finished".
There has to be an easy way to do this but my track record with Qt has always been that th
© Stack Overflow or respective owner