在你需要的地方加上如下的靜態變量:
static bool isFastClick(QObject *target, int delayTimeMil)
{
qlonglong lastTick = (target->property("tick").toLongLong());
qlonglong tick = GetTickCount();
target->setProperty("tick", tick);
if (tick - lastTick > delayTimeMil)
{
return true;
}
return false;
}
調用的地方,如下:
void MainWindow::on_pushButton_clicked()
{
bool res =isFastClick(ui->pushButton,100); //前面加上具體的按鈕名稱,後面是需要延時的時長
if(res == false) //目前是100ms
{
return;
}
}