社区
Qt
帖子详情
串口 QByteArray temp = myCom->readAll();困惑
gxlsunday
2013-08-01 03:56:58
刚学qt
看了别人写的用Qt的串口工具
QByteArray temp = myCom->readAll();
Win_QextSerialPort *myCom; 但是在这个类中没有readALL()这个成员函数
myCom->readAll();(意思难道不是调用这个类中的成员函数)
求助 谢谢
...全文
174
回复
打赏
收藏
串口 QByteArray temp = myCom->readAll();困惑
刚学qt 看了别人写的用Qt的串口工具 QByteArray temp = myCom->readAll(); Win_QextSerialPort *myCom; 但是在这个类中没有readALL()这个成员函数 myCom->readAll();(意思难道不是调用这个类中的成员函数) 求助 谢谢
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
QT
串口
通讯并进行数据库操作
void Widget::Select() //查询 { QString name = ui->lineEdit->text(); model->setFilter(QObject::tr("id = '%1'").arg(name)); //根据姓名进行筛选 model->select(); //显示结果 } void Widget::Delect() //删除当前行 { int curRow = ui->tableView->currentIndex().row(); //获取选中的行 model->removeRow(curRow); //删除该行 int ok = QMessageBox::warning(this,tr("删除当前行!"),tr("你确定" "删除当前行吗?"), QMessageBox::Yes,QMessageBox::No); if(ok == QMessageBox::No) { model->revertA
ll
(); //如果不删除,则撤销 } else model->submitA
ll
(); //否则提交,在数据库中删除该行 } void Widget::Add() //插入记录 { int rowNum = model->rowCount(); //获得表的行数 int id = 10; model->insertRow(rowNum); //添加一行 model->setData(model->index(rowNum,0),id); //model->submitA
ll
(); //可以直接提交 } void Widget::Back() //返回全表 { model->setTable("student"); //重新关联表 model->setHeaderData(0, Qt::Horizontal, "Time"); model->setHeaderData(1, Qt::Horizontal, "
Temp
erature"); model->select(); //这样才能再次显示整个表的内容 } void Widget::Amend() //提交修改 { model->database().transaction(); //开始事务操作 if (model->submitA
ll
()) { model->database().
com
mit(); //提交 } else { model->database().ro
ll
back(); //回滚 QMessageBox::warning(this, tr("tableModel"), tr("数据库错误: %1").arg(model->lastError().text())); } } void Widget::Get_time() { QString string; QTime current_time = QTime::currentTime(); int hour = current_time.hour(); int minute = current_time.minute(); int second = current_time.second(); // int msec = current_time.msec(); string=QString("%1").arg(hour)+":"+QString("%1").arg(minute) +":"+QString("%1").arg(second); ui->Receive->append(string); //qDebug()
insertRow(rowNum); //添加一行 model->setData(model->index(rowNum,0),string); model->submitA
ll
(); } void Widget::readMy
Com
() { Q
ByteArray
temp
= my
Com
->re
adA
ll
(); if(
temp
.size()!=0) { QString string; QTime current_time = QTime::currentTime(); int hour = current_time.hour(); int minute = current_time.minute(); int second = current_time.second(); // int msec = current_time.msec(); string=QString("%1").arg(hour)+":"+QString("%1").arg(minute) +":"+QString("%1").arg(second); ui->Receive->append(string); //qDebug()
insertRow(rowNum); //添加一行 model->setData(model->index(rowNum,0),string); model->setData(model->index(rowNum,1),
temp
); model->submitA
ll
(); data_light=
temp
.toInt(); } ui->Receive->append(
temp
); } void Widget::open
Com
() { QString portName = ui->portName
Com
boBox->currentText(); my
Com
= new Win_QextSerialPort(portName,QextSerialBase::EventDriven); my
Com
->open(QIODevice::ReadWrite); if(ui->baudRate
Com
boBox->currentText()==tr("9600")) my
Com
->setBaudRate(BAUD9600); else if(ui->baudRate
Com
boBox->currentText()==tr("115200")) my
Com
->setBaudRate(BAUD115200); my
Com
->setFlowControl(FLOW_OFF); my
Com
->setTimeout(500); connect(my
Com
,SIGNAL(readyRead()),this,SLOT(readMy
Com
())); ui->openMy
Com
Btn->setEnabled(false); ui->closeMy
Com
Btn->setEnabled(true); ui->baudRate
Com
boBox->setEnabled(false); ui->portName
Com
boBox->setEnabled(false); }
QT
串口
程序已16进制接受和发送数据
以16进制接受数据: //读取
串口
缓冲区的所有数据给临时变量
temp
Q
ByteArray
temp
= My
Com
->re
adA
ll
(); QDataStream out(&
temp
,QIODevice::ReadWrite); //将字节数组读入 while(!out.atEnd()) { qint8 outChar = 0; out>>outChar; //每字节填充一次,直到结束 //十六进制的转换 QString str = Q
QT4下
串口
笔记
在进行
串口
编程时,首先解决的是
串口
配置问题,这些都是由套路的哦。(使用了qextserialport) my
Com
= new Posix_QextSerialPort("/dev/ttyS0",QextSerialBase::Po
ll
ing); //定义
串口
对象,指定
串口
名和查询模式,这里使用查询方式Po
ll
ing my
Com
->open(QIODevic
QT接收到
串口
收到的十六进制数据判断问题
这个项目是移植到开发板上的程序,以前在windows下通过
串口
收到的Q
ByteArray
数据通过
temp
[i] !=0xEB这种写法没有出过错误。由于在开发板上执行,
串口
没有通过QT自带的SerialPort类接收数据,并且无法打断点,所以只能对比打印来判断。 Q
ByteArray
temp
= Q
ByteArray
(s_data);//= my
Com
->re
adA
ll
(); if(
temp
[0] != 0xEB) qDebug()<<...
TextEdit中显示数组内容
一种是参考yafeilinux的my
Com
串口
教程,显示代码如下: void Widget::readMy
Com
() //读取
串口
数据并显示出来 { Q
ByteArray
temp
= my
Com
->re
adA
ll
(); //读取
串口
缓冲区的所有数据给临时变量
temp
ui->textBrowser->insertPlainText(
temp
); //将
串口
Qt
16,200
社区成员
26,591
社区内容
发帖
与我相关
我的任务
Qt
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
复制链接
扫一扫
分享
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章