Pregunta

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.

¿Fue útil?

Solución

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;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top