Qt:显示QGraphicsItem 4秒

Qt:显示QGraphicsItem 4秒,qt,qthread,qgraphicsitem,qgraphicsscene,Qt,Qthread,Qgraphicsitem,Qgraphicsscene,我正在写一个简单的游戏,我有一个rect,我想显示几秒钟,然后消失。谁能帮帮我,怎么做?我发现,使用QThread::sleep()可以让程序等待,但我也读到,我不应该在主线程中使用它。使用QTimer::singleShot静态函数: my_item = scene->addText("test item"); QTimer::singleShot(4000, this, SLOT(hide_my_item())); 并添加插槽: void MyClass::hide_my_item(

我正在写一个简单的游戏,我有一个rect,我想显示几秒钟,然后消失。谁能帮帮我,怎么做?我发现,使用QThread::sleep()可以让程序等待,但我也读到,我不应该在主线程中使用它。

使用
QTimer::singleShot
静态函数:

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

void MyClass::hide_my_item() {
  delete my_item;
  my_item = 0;
}