//配置串口错误槽(正连接的串口拔出会出现错误)
connect(serialPort, static_cast(&QSerialPort::error), this, &MainWindow::serialPort_error);
//检测串口拔出
void MainWindow::serialPort_error(QSerialPort::SerialPortError error)
{
if (error != QSerialPort::NoError)
{
//关闭串口
serialPort->close();
}
}
扫描二维码关注公众号,回复:
16446885 查看本文章