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 display 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 display 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
If you want to display your message for 10s, the better way to do that, is to create a slot in your application that will erase the message. Then, in your button clicked slot, add your message and initialize a timer which will trigger your remove message slot in 10s:
QTimer::singleShot(10000, this, SLOT(eraseMessageSlot()));
Also, there is no need for a thread there...