从零开始实现自己的串口调试助手(4) -实现自动发送 / 时间显示

实现自动发送: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();

    });

checkBox优化:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值