我改成了这样
void MainWindow::OpenCom()
{
xx++;
if(xx%2 > 0)
{
QString portname;
portname = ComBox->currentText();
myCom = new Win_QextSerialPort(portname,QextSerialBase::Polling);
myCom->open(QIODevice::ReadWrite);
// myCom->setBaudRate((BaudRateType)fpBox->currentIndex());
myCom->setBaudRate(BAUD115200);
myCom->setDataBits(DATA_8);
//数据位设置,我们设置为8位数据位
myCom->setParity(PAR_NONE);
//奇偶校验设置,我们设置为无校验
myCom->setStopBits(STOP_1);
//停止位设置,我们设置为1位停止位
myCom->setFlowControl(FLOW_OFF);
//数据流控制设置,我们设置为硬件数据流控制
myCom->setTimeout(500);
if(myCom->isOpen())
{
Open->setText(tr("关闭串口"));
Status_temp->showMessage(tr("串口已打开"),20000);
Open->setStyleSheet("background-color:green;");
connect(myCom,SIGNAL(timeout()),this,SLOT(readMyCom()));
}
}
else
{
Open->setText(tr("打开串口"));
Open->setStyleSheet("background-color:red;");
Status_temp->showMessage(tr("串口已关闭"),20000);
myCom->close();
}
}一样的还是不行啊!。。。