这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界» 论坛首页» DIY与开源设计» 开源硬件» 跟machinnneee一起玩基于linux的QT编程(第四篇 QDir的使用)

共2条 1/1 1 跳转至

跟machinnneee一起玩基于linux的QT编程(第四篇 QDir的使用)----基于SIN210

专家
2016-08-24 08:22:26 打赏

在嵌入式开发中,如果需要记录一些数据,比如血压,血糖、心率等等,这些都是智能医疗设备所测量的数据。我们有几种方法来实现数据的存储:存放在内存中,存放在内存卡中。如果采用了嵌入式系统,那么可以建立一个文件来进行数据的存储。要创建一个文件,首先要在指定的位置进行文档的创建,那么在QT中我们采用QDir进行路径的判断。

本节课介绍一下QT文件的创建和内容的编写。

首先看源文件:

#include  #include  #include  #include  int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); // QString mStr = "hello,m.amcfsurvey.com"; QDir Mkpath; QString myPath="/home/mjl/QT_exam/lesson2/data"; if( !Mkpath.exists(myPath)) { Mkpath.mkpath(myPath); qDebug() << Mkpath.exists(myPath); } return a.exec(); }




关键词: machinnneee linux QT 编程

专家
2016-08-24 08:27:24 打赏
2楼

代码解读

#include //QT标准头文件 #include  //QT debug输出 #include  //qdir 头文件 #include  //qstring 头文件 int main(int argc, char *argv[]) //qt 标准main函数 { QCoreApplication a(argc, argv); //创建应用程序a // QString mStr = "hello,m.amcfsurvey.com";// 上一节输出字符串 QDir Mkpath; // 创建qdir 目标 QString myPath="/home/mjl/QT_exam/lesson2/data";// 要创建的文件夹 if( !Mkpath.exists(myPath)) // 检测是否存在该文件夹 如果不存在则创建 { Mkpath.mkpath(myPath);// 创建文件夹 qDebug() << Mkpath.exists(myPath);// 输出检测是否穿件成功 } return a.exec(); // a程序循环运行 }

运行该程序,则会在 /home/mjl/QT_exam/lesson2/ 下创建data的文件夹


共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册]