当前位置:网站首页>Simple read / write verification of qdatastream
Simple read / write verification of qdatastream
2022-07-01 05:06:00 【Autodesk_ Glodon】
The purpose is to write binary files and read contents :
#include <QApplication>
#include <QFile>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QFile aFile1("file.dat");
if (!(aFile1.open(QIODevice::WriteOnly)))// Open file in write only mode
return -1;
QDataStream bStream(&aFile1);
bStream.setVersion(QDataStream::Qt_5_9);
// Write the total size information space in turn , File name size information space , file name
QString currentFileName = "abcdFile" ;
qint64 v1 = 0,v2 = 0;
bStream << qint64(v1) << qint64(v2) << currentFileName;
// Cursor returns to the beginning of the file qint64 Make changes
bStream.device()->seek(0);
v1 = 13548,v2 = 8;
bStream<< qint64(v1) << qint64(v2);
// This step is to refresh the file , Let the written document take effect
aFile1.flush();
aFile1.close();
// Read dat file
QFile aFile2("file.dat");
if (!(aFile2.open(QIODevice::ReadOnly)))// Open file in write only mode
return -1;
QDataStream aStream(&aFile2);
aStream.setVersion(QDataStream::Qt_5_9);
qint64 v3 = 0,v4 = 0;
aStream >> v3 >> v4 >> currentFileName;// Reading data , Deposit in tem and str
qDebug() << v3 << v4 << currentFileName ;// Print it out and see the result
aFile2.close();
return a.exec();
}
边栏推荐
- LeetCode_66(加一)
- Global and Chinese markets of Ethernet communication modules 2022-2028: Research Report on technology, participants, trends, market size and share
- How to start learning editing? Detailed analysis of zero basis
- 线程安全问题
- Global and Chinese market of mainboard 2022-2028: Research Report on technology, participants, trends, market size and share
- Serialization and deserialization of objects
- 【暑期每日一题】洛谷 P3742 umi的函数
- 科研狗可能需要的一些工具
- 分布式锁的实现
- Sqlplus connects using the instance name
猜你喜欢
LeetCode1497-检查数组对是否可以被 k 整除-数组-哈希表-计数
Pytorch convolution operation
Manually implement a simple stack
Go learning notes (5) basic types and declarations (4)
Common methods in transforms
Solution: drag the Xib control to the code file, and an error setvalue:forundefined key:this class is not key value coding compliant for the key is reported
STM32 extended key scan
Pytoch (I) -- basic grammar
Neural networks - use of maximum pooling
Oracle views the creation time of the tablespace in the database
随机推荐
AcWing 887. Finding combinatorial number III (Lucas theorem)
Character input stream and character output stream
Unity drags and modifies scene camera parameters under the editor
RuntimeError: mean(): input dtype should be either floating point or complex dtypes. Got Long instead
【暑期每日一题】洛谷 P3742 umi的函数
分布式数据库数据一致性的原理、与技术实现方案
JS to solve the problem of floating point multiplication precision loss
智慧运维:基于 BIM 技术的可视化管理系统
对象的序列化与反序列化
STM32 extended key scan
Pico Neo3手柄抓取物体
Quelques outils dont les chiens scientifiques pourraient avoir besoin
Solution: thread 1:[< *> setvalue:forundefined key]: this class is not key value coding compliant for the key*
Global and Chinese market of paper machine systems 2022-2028: Research Report on technology, participants, trends, market size and share
科研狗可能需要的一些工具
1076 Forwards on Weibo
分布式全局唯一ID解决方案详解
AcWing 889. 01 sequence satisfying the condition (Cartland number)
缓冲流与转换流
STM32 photoresistor sensor & two channel AD acquisition