connect(&delayTimer,SIGNAL(timeout()),this,SLOT(showlcdNumber()));比如我在构造喊中写入connect,然后在代码中开启定时器,现在的问题是没有进入槽函数,我怎么判断这个定时器还在工作
可以调用QTimer类的isActive()方法
返回TRUE说明定时在工作,返回FALSE说明没有
timer.isActive()
The best thing
我在mainwindow的构造函数里写的connect是这样的connect(&delayTimer,SIGNAL(timeout()),this,SLOT(showlcdNumber()));
我在别的函数中写了开启定时器
//IO延时槽函数
void MainWindow::on_signal_delay(double num,int type)
{
delay_type = type;
delaynum = num;
ui->delay_lcdNumber->display(delaynum);
if(type == 1)
{
if(delayTimer.isActive())
delayTimer.stop();
delayTimer.start(1000);
qDebug()<<"comgingjin delay type"<<delay_type<<endl;
if(delayTimer.isActive())
qDebug()<<"delayTimer is active"<<delaynum<<endl;
ui->stop_delay->setDisabled(false);
}
else if(type == 2)
{
if(conprocess_delayTimer.isActive())
conprocess_delayTimer.stop();
conprocess_delayTimer.start(1000);
qDebug()<<"comgingjin conprocessdelay type"<<delay_type<<endl;
ui->stop_delay->setDisabled(false);
}
}
我的槽函数前面加了打印信息
void MainWindow::showlcdNumber()
{
qDebug()<<"showlcdNumber lcdnum= "<<delaynum<<endl;
if(delayTimer.isActive())
qDebug()<<"delyaTimerisliving"<<delaynum<<endl;
else
qDebug()<<"delyaTimerisnotliving"<<delaynum<<endl;
.....
}
代码运行结果是这样的
comgingjin delay type 1
delayTimer is active 2
没有进入我的槽函数,我现在的问题就是我怎么知道这个connect还工作着
调用isActive()方法啊,返回一个真假值
isActive()
更多参考:Qt之QTimer