Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在写一个简单的游戏,我有一个矩形,我想显示几秒钟,然后消失。有人可以帮我吗,怎么做?我发现,使用 QThread::sleep() 我可以让我的程序等待,但我也读过,我不应该在主线程中使用它。
使用QTimer::singleShot静态函数:
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; }