質問

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.

役に立ちましたか?

解決

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;
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top