首页 > 其他分享 >QDataStream 读取与写入QByteArray

QDataStream 读取与写入QByteArray

时间:2023-07-26 15:13:04浏览次数:39  
标签:QByteArray 读取 stream buffer bytes len returns QDataStream

问题:QDataStream中写入的数据比QByteArray多了4个byte。

仔细看了下,这个4个byte表示的是QByteArray的数据长度。

转载官方文档:https://doc.qt.io/qt-6/qdatastream.html

QDataStream &QDataStream::readBytes(char *&suint &l)

Reads the buffer s from the stream and returns a reference to the stream.

The buffer s is allocated using new []. Destroy it with the delete [] operator.

The l parameter is set to the length of the buffer. If the string read is empty, l is set to 0 and s is set to nullptr.

The serialization format is a quint32 length specifier first, then l bytes of data.

int QDataStream::readRawData(char *s, int len)

Reads at most len bytes from the stream into s and returns the number of bytes read. If an error occurs, this function returns -1.

The buffer s must be preallocated. The data is not decoded.

QDataStream &QDataStream::writeBytes(const char *suint len)

Writes the length specifier len and the buffer s to the stream and returns a reference to the stream.

The len is serialized as a quint32, followed by len bytes from s. Note that the data is not encoded.

int QDataStream::writeRawData(const char *s, int len)

Writes len bytes from s to the stream. Returns the number of bytes actually written, or -1 on error. The data is not encoded.

注意到  << 操作符 也是用的writeBytes同样的逻辑

QDataStream &QDataStream::operator<<(const char *s)

This is an overloaded function.

Writes the '\0'-terminated string s to the stream and returns a reference to the stream.

The string is serialized using writeBytes().

所以会多写一个int32在开始。

为了避免这种情况的产生,可以调用对应 W/R RawData 方法。

 

标签:QByteArray,读取,stream,buffer,bytes,len,returns,QDataStream
From: https://www.cnblogs.com/crazyghostvon/p/17582504.html

相关文章

  • 通过python读取authing IAM中的admin、user审计日志
     方式:通过python-logstash库,将读取的日志传给logstash的udpinput地址。 logstashconfig:input{udp{port=>5959codec=>json}}filter{json{source=>"message"target=>"parsed_data"}mutate{......
  • python读取rds
    Python读取RDSRDS(RelationalDatabaseService)是云计算中提供的一种托管式关系型数据库服务,它能够帮助用户轻松部署、管理和扩展关系型数据库。在Python中,我们可以使用各种库和驱动程序来连接和操作RDS。连接RDS数据库在Python中,我们可以使用第三方库mysql-connector-python来连......
  • python读取py文件
    Python读取py文件Python是一门功能强大的编程语言,可以用于开发各种类型的应用程序。在Python中,我们可以很方便地读取和操作文本文件。本文将介绍如何使用Python读取.py文件,并提供代码示例。为什么需要读取.py文件?在软件开发中,我们通常会将程序的逻辑代码保存在.py文件中。有时候......
  • python读取linux巡检
    Python读取Linux巡检作为一名经验丰富的开发者,我将教会你如何使用Python读取Linux巡检报告。下面是整个流程的步骤:步骤描述1.连接到Linux服务器使用ssh库建立与Linux服务器的连接2.执行巡检命令使用paramiko库执行巡检命令3.保存巡检结果将巡检结果保存到......
  • python读取excel为什么是小数
    Python读取Excel为什么是小数在使用Python读取Excel文件时,经常会遇到一个问题:为什么读取的数据会以小数的形式显示,而不是原始的整数或文本呢?这个问题涉及到Python读取Excel的原理以及Excel中的数据类型的转换。Excel中的数据类型在Excel中,每个单元格都有自己的数据类型。常见的......
  • python读取TXT文件第二行
    Python读取TXT文件第二行引言作为一名经验丰富的开发者,我很高兴能够帮助你解决问题。在本文中,我将向你解释如何使用Python读取TXT文件的第二行。我将提供一条清晰的步骤,以及每一步所需要的代码和对其含义的注释。问题背景在开始之前,让我们先来了解一下你的问题背景。你想要读取......
  • WEB漏洞—文件操作之文件下载读取
    文件下载,读取原理,检测,利用,修复等#利用数据库配置文件下载或读取后续接口密匙信息文件下载或读取后续#文件名,参数值,目录符号read.xxx?filename=down.xxx?filename=readfile.xxx?file=downfile.xxx?file=../..\.\./等%00?%23%20.等&readpath=、&filepath=、&......
  • 使用Python读取txt中的指定内容
    一、序在一些情况下,导出txt的配置信息,但是又有特定的规律。在这种情况下读取配置二、问题分析我们首先肯定是通过关键字定位文本位置,但txt文件我们会面临两种情况:1.关键字与文本在同一行2.关键字与文本不在同一行3.判断条件例如MAC地址只有有IP的才读取,没有IP的就......
  • SAP ABAP 传输请求背后的读取函数和存储数据库表讲解试读版
    本教程前一篇文章,我们介绍了SAPABAP系统传输请求的基本知识:106.什么是SAPABAP系统里的传输请求(TransportRequest)有朋友提问:你好,有个问题请教下,在开发系统通过SM30维护会产生传输请求的配置表,这个传输请求对应的本次修改的内容存在哪里的呢?SE09相关CR里只有配置表......
  • ANSI编码的csv文件python怎么读取
    ANSI编码的csv文件python怎么读取在使用Python读取CSV文件时,常见的文件编码格式有UTF-8、GBK等,但有时我们可能会遇到一些使用ANSI编码的CSV文件,这会导致读取文件时出现乱码问题。问题描述假设我们有一个使用ANSI编码的CSV文件,我们希望能够正确地读取其中的数据,并进行后续的处理......