请教一个问题,QBytearray若是作为函数返回值的时候,
若是读取的是空,他实际返回的是啥,是0,还是null
QBytearray rx_data = now_serial.readAll();//读取串口数据。
QByteArray QIODevice::readAll()
Reads all remaining data from the device, and returns it as a byte array.
This function has no way of reporting errors; returning an empty QByteArray can mean either that no data was curr ently available for reading, or that an error occurred.
就是返回一个QByteArray()
参考GPT和自己的思路:
如果使用QBytearray作为函数返回值读取一个空数据时,函数将会返回一个空的QByteArray。这就意味着函数无法报告错误,并且返回的QByteArray为空,这可能是因为没有当前可读取的数据,或者是出现了错误。因此,当使用这种函数时,需要在接收到空QByteArray时进行错误处理。
不是0也不是null
而是一个包含了0个元素的QBytearray对象