QSocketNotifier丢数据

1,遇到这个问题

用QSocketNotifier监测串口读取数据 http://bbs.embedsky.net/forum.php?mod=viewthread&tid=9066

相应的解决方法:没

QSocketNotifier监测串口问题http://www.qtcn.org/bbs/read-htm-tid-36369-displayMode-1-page-1.html#133140

相应的解决方法:

使用这个要遵循三步:
1、Disable the notifier.
2、Read data from the socket.
3、Re-enable the notifier if you are interested in more data


2,看看是不是我的校验的问题,置位校验都取消看看

果真如此:

i1:0

JIN_remoteDataIncoming

handleData:OK

read_buf:134521496

i1:1

JIN_remoteDataIncoming

handleData:OK

read_buf:134521496

i1:2

JIN_remoteDataIncoming

handleData:OK

read_buf:134521496

i1:3

JIN_remoteDataIncoming

handleData:OK

read_buf:134521496

i1:4

不过 还有一个问题就是,如果读多个数据怎么办?

①:http://blog.chinaunix.net/uid-24948299-id-2899775.html

void MainWindow::read_serial()
{ 
QByteArray temp=myCom->readAll();//全部读取
ui->textEdit->insertPlainText(temp);//显示读取到的数据
}

②:还是回到上边的问题中,想办法Disable

m_notifier->setEnabled(false);//不使能

m_notifier->setEnabled(true);  //使能

结论:禁止是能禁止了,不过效果没有达到!还是一个数据就激活一次!

③:

void TMainForm::remoteDataIncoming()
{
char c;
if (read(m_fd, &c, sizeof c) != 1) {
QMessageBox::warning(this, tr("Error"), tr("Receive error!"));
return;
}
m_receiveEdit->insert(QString(QChar(c)));
}

仔细读这段代码时,并加上亲自实验,每次读一个字节是就最好的办法了,我可以让它们累加到数组中去!

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

袁保康

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值