bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result) { Q_UNUSED(result); Q_UNUSED(eventType); MSG* pMsg = reinterpret_cast<MSG*>(message); if (pMsg->message == WM_KEYUP) { ushort key = pMsg->wParam; if (key == '\r') { ui->sn_lineEdit->setText(m_scanSN); m_scanSN = ""; } else { //可见字符 if (key >= 32 && key < 127) { m_scanSN = m_scanSN + QChar(key); } } } if(pMsg->message == WM_DEVICECHANGE){ PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)pMsg->lParam; switch (pMsg->wParam) { case DBT_DEVICEARRIVAL: if(lpdb->dbch_devicetype == DBT_DEVTYP_PORT){ qDebug()<<"插入串口设备!"; emit signalUpdataSerialPort(); } break; case DBT_DEVICEREMOVECOMPLETE: if(lpdb->dbch_devicetype == DBT_DEVTYP_PORT){ qDebug()<<"串口设备离开"; m_SerialPort.closeSerialPort(); ui->openSerialport_Btn->setText("打开串口"); m_serialPortStatus = false; logMessage("关闭串口"); emit signalUpdataSerialPort(); } } } return false; }
标签:插拔,扫码,scanSN,pMsg,key,串口,message,DBT From: https://www.cnblogs.com/RedWetPlace/p/18324868