Qt5串口通信(二)

本文介绍了在Qt5中使用QIODevice的write函数进行串口通信时,如何判断数据写入是否成功。通过测试不同场景(单片机断电和供电),作者发现使用int、bool和qint64类型检测write函数的返回值可能存在误导,因为在某些情况下,返回值可能并不准确地反映写入状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Qt串口mycom->write()函数写入失败的判断 

/********************************************************************/

******************by: dxsdcxy*************************************

********************************************************************/

官方文档解释:

Version:1.0 StartHTML:0000000105 EndHTML:0000009512 StartFragment:0000000127 EndFragment:0000009494 


qint64 QIODevice::write ( const char * data, qint64 maxSize )

Writes at most maxSize bytes of data from data to the device. Returns the number of bytes that were actually written, or -1 if an error occurred.

See also read() and writeData().

qint64 QIODevice::write ( const char * data )

This is an overloaded function.

Writes data from a zero-terminated string of 8-bit characters to the device. Returns the number of bytes that were actually written, or -1 if an error occurred. This is equivalent to

 ... 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值