Question

I'm writing a simple game, and I have a rect, that I want to display for a few secs, and then disappear. Could someone help me, how to do this? I found, that with QThread::sleep() I can make my program wait, but I also have read, that I shouldn't use it in the main thread.

Was it helpful?

Solution

Use QTimer::singleShot static function:

my_item = scene->addText("test item");
QTimer::singleShot(4000, this, SLOT(hide_my_item()));

And add the slot:

void MyClass::hide_my_item() {
  delete my_item;
  my_item = 0;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top