18.QT中的write函数

今天在传输文件的时候,发现运行后,文件是过来了,但又没完全过来,文件的大小只有几kb,而原文件几m.
后面发现write函数用错了,
1.write(const char *data),
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.
大概意思就是写入以0结尾的字符串。
相当于:QIODevice::write(data, qstrlen(data));
而qstrlen:
Returns the number of characters that precede the terminating ‘\0’, or 0 if str is 0.

错的原因应该就是存在换行,暂时低层还不清楚

2.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.
则表示输入max个字节(byte)的数组(比如一个字符就是1byte,如果是汉字,则是2byte),bit是位,byte是字节。
想要完全写入自己的内容,且内容较大时,最好用这个。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值