Qt读取串行输入,然后将其拆分为单独的变量
Qt reading serial input then splitting it into separate variables
我正在研究Qt,但是我遇到了一个我一生都无法解决的问题。我已经尝试了许多不同的代码组合,但它仍然没有给我我正在寻找的输出。我希望有人能帮助我。
QStringList buffer_split = serialBuffer.split(","); // split the serialBuffer string, parsing with ',' as the separator
// Check to see if there less than 3 tokens in buffer_split.
// If there are at least 3 then this means there were 2 commas,
// means there is a parsed temperature value as the second token (between 2 commas)
if(buffer_split.length() < 3){
// no parsed value yet so continue accumulating bytes from serial in the buffer.
serialData = arduino->readAll();
serialBuffer = serialBuffer + QString::fromStdString(serialData.toStdString());
serialData.clear();
}else{
// the second element of buffer_split is parsed correctly, update the temperature value on temp_lcdNumber
serialBuffer = "";
qDebug() << buffer_split << "n";
parsed_data = buffer_split[1];
}
上述解决方案对我有用,反过来我正在读取通过串行端口发送的值,例如:
0,0,0,0,0,0
以上是parsed_data
如何从串行端口读取信息,这是正确的。
我遇到的问题是拆分它,然后将它们存储在单独的变量中以启动一些 if 语句。 到目前为止,我似乎无法让它工作。
如果有人可以帮助我,我将不胜感激
谢谢
你不需要额外的parsed_data
变量buffer_split
存储它们,你只需要int num1 = buffer_split[0].toInt(); int num2 = buffer_split[1].toInt();
相关文章:
- 如何在C++中从两个单独的for循环中添加两个数组
- 用C++在单独的头文件中完成函数体
- 类模板的成员功能的定义在单独的TU中完全专业化
- 如何使用单独文件中的派生类访问友元函数对象
- CoInitialize()在单独的线程上崩溃而不返回
- C++将向量的向量拆分为向量的N个子向量
- avrogencpp能为模式中的每种类型生成单独的头文件吗
- 如何拆分文件中.txt字母并使用c ++使用数组进行扑克?
- 转换函数,将 std::数组的双精度作为参数或双精度作为参数单独转换
- 将字符串拆分为标记,并将标记拆分为两个单独的数组
- 将耦合类拆分为单独的标头
- Qt读取串行输入,然后将其拆分为单独的变量
- 在 c++ 中将字符串拆分为单独的变量
- 如何将__DATE__和__TIME__宏拆分为变量声明的单独组件
- 将从视频获得的帧拆分为单独的通道
- 如何将字符串(没有空格)拆分为单独的字符串
- 如何在单独的 Boost.Python 模块之间拆分继承关系
- 如何拆分C++字符串以单独获取整个字符串及其某些部分/字符
- 将单独文本文件的段落拆分为单独的字符串
- 如何将路径拆分为单独的字符串