Qtimer 问题,设置单次定时,但是slot槽程序被执行两遍?
void MainWindow::on_newPushButton_clicked()
{
if(ui->checkBox->isChecked())
{
this->hide();
this->timer=new QTimer;
QObject::connect(this->timer,SIGNAL(timeout()),this,SLOT(shotScreenSlot()));
this->timer->start(ui->delaySpinBox->value()*1000);//设置延时时间
this->timer->setSingleShot(true);
}else
{
qApp->beep();
}
}
void MainWindow::shotScreenSlot()
{
this->timer->stop();//测试了这个几乎不起作用,如果在上面不设置单次触发,那么会周期触发的
this->pixmap=QPixmap::grabWindow(QApplication::desktop()->winId());
ui->screenLabel->setPixmap(this->pixmap.scaled(ui->screenLabel->size()));
qDebug()<<"****";//测试slot函数进入几次
this->show();
}