实现自动发送:checkBox
添加bool槽函数

bool 值,当√的时候为true
取消√ 位false

实现带bool 类型的槽函数:
void Widget::on_checkBox_SendInTime_clicked(bool checked)
{
qDebug()<<"checkStatus:"<<checked;
if(checked){ // 被勾选了
//发送一次
//on_btnSendContext_clicked();
timer->start(ui->lineEdit_TimeEach->text().toInt()); // 读取框内的内容,更新发生频率
// 发生的时候这两选择不能被修改
ui->lineEdit_TimeEach->setEnabled(false);
ui->lineEdit_SendContext->setEnabled(false);
}
else{// √取消就不发送
timer->stop();
ui->lineEdit_TimeEach->setEnabled(true);
ui->lineEdit_SendContext->setEnabled(true);
}
}
关联信号与槽: 定时器的使用
头文件定义:
QTimer *timer;
构造函数初始化
timer = new QTimer(this);
// 关联信号与槽 --每次到点就发送一次
connect(timer,&QTimer::timeout,[=](){
on_btnSendContext_clicked();
});

最低0.47元/天 解锁文章
1010

被折叠的 条评论
为什么被折叠?



