Qt如何读取数据文件

Qt如何读取数据文件,第1张

#include <QFile>

#include <QString>

#include <QIODevice>

#include <QDebug>

#include <QTextStream>

void Read(QString Filename)//名字自己定,需要带路径

{

QFile mFile(Filename)

if(!mFile.open(QFile::ReadOnly|QFile::Text))

{

qDebug()<<"could not open file for read!"

return

}

QTextStream in(&mFile)

QString mtext = in.readAll()

// mtext = mtext.trimmed()

qDebug()<<mtext

if(mtext == "")

qDebug()<<" read over!"

mFile.flush()

mFile.close()

}

1、使用QDataStream进行二进制数据读写。

2、read binary data from a stream。

3、在代码中使用硬编码指定流的版本号。

4、在文件头写入一个简短的幻数字符串和一个版本数字,来用于将来扩展。

5、可以以下面这种方式来读取。

6、使用事务来完成不完整的数据读取。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/11997402.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存