我正在尝试用c++重写一个用python编写的应用程序。
它所做的就是打开一个串口并读取一些xml。在python中,我使用pyserial读取xml,使用漂亮汤检索信息。输出是这样的。
<file><property>xx32</property></file>现在,我使用qextserialport从串口读取数据,得到的xml如下所示。
<
fil
e>
<prope
rty>xx32
</prop
erty>
</
file>我的问题是我不能像这样解析xml。我会犯错。
编辑:
Qextserialport端口以一组未固定的字节从串口读取数据。那么,如何将xml连接成一个字符串呢?我每4-5秒从串口得到一个xml字符串。
这是我的密码
this->port = new QextSerialPort(com_port,QextSerialPort::EventDriven);
port->setBaudRate(BAUD57600);
port->setFlowControl(FLOW_OFF);
port->setParity(PAR_NONE);
port->setDataBits(DATA_8);
port->setStopBits(STOP_1);
port->setTimeout(0);
if (port->open(QIODevice::ReadOnly) == true)
{
//qDebug()<< "hello";
connect(port,SIGNAL(readyRead()),this,SLOT(onReadyRead()));
}以及实际从串口读取的函数。
void CurrentCost::onReadyRead()
{
QByteArray bytes;
bytes = port->readAll();
//qDebug() << "bytes read:" << bytes.size();
//qDebug() << "bytes:" << bytes;
ui->textBrowser->append(bytes);
}发布于 2011-07-09 17:00:44
我的意思是这样的:
class CurrentCost...{
private:
QByteArray xmlData;
private slots:
void onReadyRead();
};
void CurrentCost::onReadyRead()
{
xmlData.append(port->readAll());
if(xmlData.endsWith(/*what your port sending then xml is over&*/))
{
ui->textBrowser->append(xmlData);
xmlData.clear();
}
}https://stackoverflow.com/questions/6634432
复制相似问题