当前位置:网站首页>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();
}
边栏推荐
猜你喜欢

STM32扩展版 按键扫描

分布式事务-解决方案

Pytorch convolution operation

STM32 光敏电阻传感器&两路AD采集

LeetCode316-去除重复字母-栈-贪心-字符串

C# wpf 使用DockPanel实现截屏框

Manually implement a simple stack

Leetcode1497- check whether array pairs can be divided by K - array - hash table - count

分布式-总结列表

Use of STM32 expansion board temperature sensor and temperature humidity sensor
随机推荐
Global and Chinese markets for business weather forecasting 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of high-end home theater 2022-2028: Research Report on technology, participants, trends, market size and share
Design experience of Meizhou clinical laboratory
Neural network convolution layer
Thoughts on the construction of Meizhou cell room
FileInputStream
LeetCode_ 28 (implement strstr())
LeetCode1497-检查数组对是否可以被 k 整除-数组-哈希表-计数
Global and Chinese market of 3D design and modeling software 2022-2028: Research Report on technology, participants, trends, market size and share
分布式锁的实现
Pytorch neural network construction template
Global and Chinese market of mainboard 2022-2028: Research Report on technology, participants, trends, market size and share
分布式全局唯一ID解决方案详解
Go learning notes (5) basic types and declarations (4)
解决qiankun中子应用外链文件无法获取
Single page application
LeetCode316-去除重复字母-栈-贪心-字符串
如何开始学剪辑?零基础详细解析
线程类的几大创建方法
如何选择导电滑环材料