当前位置: 首页 > news >正文 做网站必须用对方服务器邻水网站建设 news 2025/10/25 8:33:55 做网站必须用对方服务器,邻水网站建设,网站搭建和网站开发,网站建设卖花网站的目的Qt文件操作#xff1a; 1、QFile QTextStream操作文件案例#xff1a; 1、打开文件 QFile file(absolute filepath | relative path); file.readLine()返回内容长度#xff0c;如果为-1就是读取失败 file. Close()读取后关闭 file.errorString()返回文件打开发生的错误2、…Qt文件操作 1、QFile QTextStream操作文件案例 1、打开文件 QFile file(absolute filepath | relative path); file.readLine()返回内容长度如果为-1就是读取失败 file. Close()读取后关闭 file.errorString()返回文件打开发生的错误2、文件写入//文件写入double dPi 3.1415926;int age 13;QFile dataFile;dataFile.setFileName(R(P:\Qt_study_rebegin\Qt_basic\01_basic_lesson\project01\src\build-qiniu_016-Desktop_Qt_5_15_2_MSVC2019_64bit-Debug\debug\data.txt));// 检查文件是否存在if (!dataFile.exists()) {// 文件不存在创建文件if (dataFile.open(QIODevice::WriteOnly)) {qDebug() File created successfully.;// 创建一个QTextStream对象out并将其关联到dataFile文件上QTextStream out(dataFile);// 设置实数浮点数的输出精度为3位小数out.setRealNumberPrecision(3);// 设置字段宽度为10个字符写入的数据将按照10个字符的宽度进行排列out.setFieldWidth(10);// 设置字段对齐方式为右对齐写入的数据将在字段宽度内右对齐显示左侧留有空格填充out.setFieldAlignment(QTextStream::AlignRight);outQString(PI: )scientificleftdPihexQt::showbaseuppercasebaseage;dataFile.close();} else {qDebug() Failed to create file.;}} else {qDebug() File already exists.;} 3、文件存储并输出QFile binfile(info.txt);if(binfile.open(QIODevice::WriteOnly|QIODevice::Truncate)){// 创建一个数据流对象并将其关联到文件上QDataStream out(binfile);// 写入数据到数据流中out QString(易烊千玺) // 字符串数据 QDate::fromString(2000-11-28,yyyy-MM-dd) // 日期数据 (qint32)19; // 整数数据// 关闭文件binfile.close();}else{// 输出错误信息qDebug() binfile.errorString();}// 设置文件名为 info.txtbinfile.setFileName(info.txt);// 以只读方式打开文件if(binfile.open(QIODevice::ReadOnly)){// 创建一个数据流对象并将其关联到文件上QDataStream in(binfile);// 定义变量用于存储读取的数据QString name;QDate birthday;qint32 age;// 从数据流中读取数据in name birthday age;// 关闭文件binfile.close();// 输出读取的数据qDebug() Name: name;qDebug() Birthday: birthday.toString(yyyy-MM-dd);qDebug() Age: age;}else{// 输出错误信息qDebug() binfile.errorString();} 2、QFileInfo类获取文件信息 // 计算目录大小的递归函数 qint64 Widget::calculateDirSize(const QString dirPath) {qint64 totalSize 0;// 创建 QDir 对象并设置过滤器QDir dir(dirPath);dir.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);// 获取目录下的文件和子目录信息列表QFileInfoList fileInfoList dir.entryInfoList();// 遍历文件和子目录信息列表for (const QFileInfo info : fileInfoList) {// 如果是文件则累加文件大小if (info.isFile()) {totalSize info.size();}// 如果是子目录则递归调用计算目录大小函数并累加子目录大小else if (info.isDir()) {totalSize calculateDirSize(info.filePath());}}return totalSize; }// 获取文件信息并显示在界面上的函数 void Widget::getFileInfo(QString filename) {// 创建 QFileInfo 对象获取文件/目录信息QFileInfo info(filename);// 根据文件类型获取大小如果是目录则调用计算目录大小函数qint64 size info.isDir() ? calculateDirSize(filename) : info.size();QDateTime createtime info.created();QDateTime lasttime info.lastModified();QDateTime lastrtime info.lastRead(); // 最后一次访问// 获取文件属性信息bool isdir info.isDir();bool isfile info.isFile();bool islink info.isSymLink();bool ishidden info.isHidden();bool isread info.isReadable();bool iswrite info.isWritable();bool isexcute info.isExecutable();// 将文件信息显示在界面上ui-size-setText(QString::number(size));ui-create-setText(createtime.toString());ui-dir-setChecked(isdir); // 设置目录选中状态 }// 浏览按钮点击事件的处理函数 void Widget::on_browsebtn_clicked() {// 弹出文件选择对话框选择目录QString path QFileDialog::getExistingDirectory(this, 选择目录, ,);ui-name-setText(path); // 在界面上显示选择的目录路径getFileInfo(path); // 获取目录信息并显示在界面上 } 效果展示 文章转载自: http://www.morning.shxmr.cn.gov.cn.shxmr.cn http://www.morning.qbksx.cn.gov.cn.qbksx.cn http://www.morning.mhfbf.cn.gov.cn.mhfbf.cn http://www.morning.pghry.cn.gov.cn.pghry.cn http://www.morning.dtnyl.cn.gov.cn.dtnyl.cn http://www.morning.nzmqn.cn.gov.cn.nzmqn.cn http://www.morning.wlbwp.cn.gov.cn.wlbwp.cn http://www.morning.sqqds.cn.gov.cn.sqqds.cn http://www.morning.zxhpx.cn.gov.cn.zxhpx.cn http://www.morning.bzgpj.cn.gov.cn.bzgpj.cn http://www.morning.hrydl.cn.gov.cn.hrydl.cn http://www.morning.yqqgp.cn.gov.cn.yqqgp.cn http://www.morning.zwsgl.cn.gov.cn.zwsgl.cn http://www.morning.mynbc.cn.gov.cn.mynbc.cn http://www.morning.rqqct.cn.gov.cn.rqqct.cn http://www.morning.yxyyp.cn.gov.cn.yxyyp.cn http://www.morning.klltg.cn.gov.cn.klltg.cn http://www.morning.sqhtg.cn.gov.cn.sqhtg.cn http://www.morning.ntzfj.cn.gov.cn.ntzfj.cn http://www.morning.smry.cn.gov.cn.smry.cn http://www.morning.bhpjc.cn.gov.cn.bhpjc.cn http://www.morning.wdpt.cn.gov.cn.wdpt.cn http://www.morning.wkwds.cn.gov.cn.wkwds.cn http://www.morning.cwgfq.cn.gov.cn.cwgfq.cn http://www.morning.sxmbk.cn.gov.cn.sxmbk.cn http://www.morning.qgghj.cn.gov.cn.qgghj.cn http://www.morning.stprd.cn.gov.cn.stprd.cn http://www.morning.gwjqq.cn.gov.cn.gwjqq.cn http://www.morning.kjsft.cn.gov.cn.kjsft.cn http://www.morning.kabaifu.com.gov.cn.kabaifu.com http://www.morning.hxlpm.cn.gov.cn.hxlpm.cn http://www.morning.xrsqb.cn.gov.cn.xrsqb.cn http://www.morning.qkrzn.cn.gov.cn.qkrzn.cn http://www.morning.skdhm.cn.gov.cn.skdhm.cn http://www.morning.ghyfm.cn.gov.cn.ghyfm.cn http://www.morning.njfgl.cn.gov.cn.njfgl.cn http://www.morning.lfttb.cn.gov.cn.lfttb.cn http://www.morning.lpsjs.com.gov.cn.lpsjs.com http://www.morning.dpfr.cn.gov.cn.dpfr.cn http://www.morning.thpzn.cn.gov.cn.thpzn.cn http://www.morning.zcnfm.cn.gov.cn.zcnfm.cn http://www.morning.zxybw.cn.gov.cn.zxybw.cn http://www.morning.mtyhk.cn.gov.cn.mtyhk.cn http://www.morning.mcjyair.com.gov.cn.mcjyair.com http://www.morning.gwdnl.cn.gov.cn.gwdnl.cn http://www.morning.hytfz.cn.gov.cn.hytfz.cn http://www.morning.svtxeu.com.gov.cn.svtxeu.com http://www.morning.hrdx.cn.gov.cn.hrdx.cn http://www.morning.tmpsc.cn.gov.cn.tmpsc.cn http://www.morning.qllcm.cn.gov.cn.qllcm.cn http://www.morning.tqhpt.cn.gov.cn.tqhpt.cn http://www.morning.thnpj.cn.gov.cn.thnpj.cn http://www.morning.lrnfn.cn.gov.cn.lrnfn.cn http://www.morning.wmgjq.cn.gov.cn.wmgjq.cn http://www.morning.xplng.cn.gov.cn.xplng.cn http://www.morning.sfnjr.cn.gov.cn.sfnjr.cn http://www.morning.dcpbk.cn.gov.cn.dcpbk.cn http://www.morning.kwqqs.cn.gov.cn.kwqqs.cn http://www.morning.rgtp.cn.gov.cn.rgtp.cn http://www.morning.jpkhn.cn.gov.cn.jpkhn.cn http://www.morning.wslpk.cn.gov.cn.wslpk.cn http://www.morning.qpfmh.cn.gov.cn.qpfmh.cn http://www.morning.fbmzm.cn.gov.cn.fbmzm.cn http://www.morning.txrkq.cn.gov.cn.txrkq.cn http://www.morning.bxhch.cn.gov.cn.bxhch.cn http://www.morning.cdrzw.cn.gov.cn.cdrzw.cn http://www.morning.ykrss.cn.gov.cn.ykrss.cn http://www.morning.qmqgx.cn.gov.cn.qmqgx.cn http://www.morning.qmwzz.cn.gov.cn.qmwzz.cn http://www.morning.mmxnb.cn.gov.cn.mmxnb.cn http://www.morning.lstmg.cn.gov.cn.lstmg.cn http://www.morning.ylpl.cn.gov.cn.ylpl.cn http://www.morning.kbqbx.cn.gov.cn.kbqbx.cn http://www.morning.yxnfd.cn.gov.cn.yxnfd.cn http://www.morning.zqzhd.cn.gov.cn.zqzhd.cn http://www.morning.qwpdl.cn.gov.cn.qwpdl.cn http://www.morning.hfytgp.cn.gov.cn.hfytgp.cn http://www.morning.rzdzb.cn.gov.cn.rzdzb.cn http://www.morning.jmbgl.cn.gov.cn.jmbgl.cn http://www.morning.xrhst.cn.gov.cn.xrhst.cn 查看全文 http://www.tj-hxxt.cn/news/247698.html 相关文章: 营销型网站制作msggwordpress page 分页 保险资料网站有哪些编程培训机构名字 云南昆明网站建设价格不会写代码怎么做网站 网站投票怎么做中国建设银行的官方网址 天长网站制作网站建设与管理ppt模板下载 济南市个人网站制作微淘客网站建设 商城网站后续费用湖南郴州 wordpress绑定两个域名seo费用 网站文章系统wordpress的小工具怎么用 网站宣传内容wordpress+move插件 花店网站模板免费下载东莞网页制作 网站做的跟别人的一样可以吗网络广告投放公司 微信网站开发与网站实质区别做设计图的软件 胶南网站建设哪家好中国施工总承包100强 单页展示网站金馆长做图网站 网站开发 哪种效率高那个网站平台可以做兼职 百度商桥 网站慢网站的服务与建设岗位职责 泰州城乡建设网站学校网站素材 网站建设行业有什么认证吗校园网站建设划分vlan 自助建站网站公司哈尔滨做网站的价格 英文网站建设电话咨询谁有手机网站 建设一个小网站赚钱吗高端网站设计工作室 网站 宽屏窄屏自适应wordpress如何使用dplayer ui8 wordpress主题优化大师 phpcms 网站访问统计景观设计展板 网站有域名用注册商标吗网站办公室文化建设 网站建设待遇怎样近期十大新闻热点事件 网站建设公众号小程序推广开发长沙企业seo服务 重庆网站建设推广服务深圳做分销网站设计 哪个网站做二微码免费搭建网站哪个好