QT检测当前连接的串口是否拔出

//配置串口错误槽(正连接的串口拔出会出现错误)

connect(serialPort, static_cast(&QSerialPort::error), this, &MainWindow::serialPort_error);

//检测串口拔出

void MainWindow::serialPort_error(QSerialPort::SerialPortError error)

{

        if (error != QSerialPort::NoError)

        {

                //关闭串口

                serialPort->close();

        }

}

扫描二维码关注公众号,回复: 16446885 查看本文章

猜你喜欢

转载自blog.csdn.net/weixin_39457767/article/details/130892204