Qt创建文件夹 QDir类

使用Qt的QDir/QFile类创建文件夹、以时间命名的dat/txt等文件、从文件中读写数据等操作 一、创建文件夹 二、创建文件 三、创建文件夹和文件的函数实现 四、将数据写入文件 五、从文件中读取数据 阅读详情

首先创建一个lineEdit和pushButton成员变量和一个createFolderSlot()槽函数

private:
    QLineEdit *lineEdit;
    QPushButton *pushButton;
private slots:
    void createFolderSlot();

构造函数中:

    lineEdit = new QLineEdit(this);
    lineEdit->setGeometry(QRect(50, 50, 200, 25));
    pushButton = new QPushButton(this);
    pushButton->setGeometry(QRect(280, 50, 80, 25));
    pushButton->setText("Create");
    connect(pushButton, &QPushButton::clicked, this, &MainWindow::createFolderSlot);

槽函数实现:

void MainWindow::createFolderSlot()
{
    QDir *folder = new QDir;
    bool exist = folder->exists(lineEdit->text());
    if(exist)
    {
        QMessageBox::warning(this, tr("createDir"), tr("Dir is already existed!"));
    }
    else
    {
        //创建文件夹
        bool ok = folder->mkdir(lineEdit->text());
        if(ok)
            QMessageBox::warning(this, tr("CreateDir"), tr("Create Dir success!"));
        else
            QMessageBox::warning(this, tr("CreateDir"), tr("Create Dir fail"));
    }
}

如下图,输入要创建的文件夹的路径,点击Create创建

11、Qt:创建/删除文件夹、拷贝文件 Qt使用QDir、QFile、QFileInfo等类对文件和文件夹进行操作 阅读详情

相关推荐

Qt文件以及文件夹相关类(QDir、QFile、QFileInfo)的使用

本文主要总结一下文件夹以及文件相关类的一些使用方法。

苍天愚弄我 2980

Qt:创建文件夹QDir

Qt:创建文件夹QDir。

Healer_CC的博客 2894

Qt基础-项目中添加文件夹及子文件

本文讲解Qt项目中添加文件夹及子文件

qq_30725967的博客 5194

QT 文件夹操作

的区别,如果需要创建一个父目录不存在的目录,就使用mkpath,否则会导致新建文件夹不成功,下面是(在当前应用程序目录下创建一个test文件夹)

m0_63647324的博客 4425

qt中建立文件夹并且在文件夹中建立txt文档

使用qt新建一个文件夹,并在文件夹中建立一个text文件

从理论到代码:蒙特卡洛法在光学散射模拟中的应用全解析(Matlab 2014a版)

本文详细解析了蒙特卡洛法在光学散射模拟中的应用,从数学原理到Matlab 2014a实现。通过模拟光子随机游走过程,精确描述光在浑浊介质中的传输特性,提供完整的源码实现和性能优化技巧,适用于生物医学光学、大气遥感等领域。

rum55的博客 627

Qt下每天自动创建日期文件

文章目录前言一、需要哪些类实现该功能?1. QTime类2. QTimer类3. QDir类4. QFile类二、如何实现1.实例化定时器对象,绑定信号和槽2.判断是否到达新的一天3.创建新的文件夹和文件总结 前言 在进行项目开发时,我们可能要将日志文件长期保存(本文不谈QT自带的日志类),并按照/2020/09/09-11/log.txt这种模式保存,或者保存某些信息时要求保存的文件自动按时间分类,那我们就需要在每天00:00:00时创建新的文件夹和文件。 一、需要哪些类实现该功能? 1. QTim.

weixin_44894312的博客 2864

Codex登录要手机验证码?Cockpit Tools跳过验证保姆级教程

摘要:OpenAI升级风控后,Codex登录需手机验证,增加批量账号使用成本。CockpitTools(GitHub 8.3k star)可绕过验证,支持多AI编程平台账号管理。操作步骤:1) 获取ChatGPT网页Session数据;2) 通过转换工具生成CPA格式JSON;3) 导入工具启动Codex。注意:仅适用于未绑定手机号的账号,Session会过期,且需防范数据泄露风险。商业账号通常直接提供认证文件。(150字)

5840

Qt程序设计——文件/文件夹的创建

引言: QT中需要设计到文件管理时,包括文件的和文件夹的创建及获取,需要用到QDir类,必要时要跟QFile等类结合使用。 1.创建文件夹 假设在目录dir下创建新的文件夹,文件夹名为test QDir dir("....");//输入dir的路径,也可以通过QFielDialog获取 dir.mkdir("test")//在目录dir下创建子目录test QString test_p

luo_klt 2146

mysql 计算不同胜率的活跃玩家的次日,3日,7日留存率

它根据每天的日期(logymd)和最高段位(max_rank)、胜率段落(win_rate_segment)进行分组,并计算总玩家人数(total_players)、第二天的留存人数(next_day_players)、第三天的留存人数(day3_players)和第七天的留存人数(day7_players)。注意:不是新手留存,是段位活跃玩家留存;最终的结果则是将留存数据进行展示,按照日期(date)、最高段位(rank_level)、胜率段落(win_rate_segment)进行排序。

weixin_42698221的博客 1836

图像去雨:超详细手把手写 pytorch 实现代码(带注释)

占个坑,过几天来写

书山有路,学海无涯! 1万+

Qt使用QDir创建时间相关文件目录及遍历文件夹

使用QDateTime和QDir创建当前日期、时间相关的文件目录,遍历文件夹的方法

qq_45194239的博客 2011

Trae的付费之路还挺艰难,茫茫多的人想付付不了(附解决办法)

不得不说,Trae国际版这个付费其实整的挺复杂的,但没办法,毕竟有政策限制,付费成功后,你就是尊贵的Pro用户啦,使用Claude 4不排队还是挺爽的,而且600次其实不算少了,有一个小技巧,简单的问题就把模型切到Gemini-2.5-flag,因为使用这个模型是没有次数限制的。其次付费的时候有个ZIP Code,这东西也是个迷之存在,有的地区节点需要填,有的不需要,如果你选到了不需要填的节点,那很好,付费就行了,如果需要填,可以填一个51800试试。

cpp加油站的专栏 5879

Qt 判断文件或文件夹是否存在及创建文件夹

1. 判断文件夹是不是存在 参数说明: QString fullPath;//文件夹全路径 /*方法1*/ bool isDirExist(QString fullPath) {     QDir dir(fullPath);     if(dir.exists())     {       return true;     }     return false; } /

lusirking的博客 7万+

S7-200SMART 的运动控制(一)向导配置具体步骤(图文)

S7-200SMART 的运动控制(一)向导配置具体步骤(图文)

Robot_PLC_HMI_Automation 3849

【maven】idea左侧External Libraries里,没有Maven的依赖包 代码飘红

文章目录1.概述M.参考 1.概述 因为内网开发,然后这几天我被隔离了,然后公司搞了一个外网的vpn能连接的云桌面,云桌面也是网络隔离的,因此只能自己拷贝相关的文件到里面。 然后我就拷贝了代码和maven仓库中的一部分,因为本地的20G一次拷贝不完,需要多次拷贝,但是我拷贝了kafka,仍然飘红。具体如下 idea左侧External Libraries里,没有Maven的依赖包 然后整了很久都没搞定,后来我自己新建了一个项目,然后引入发现是不可以的,而且框框里面的飘红。 然后我就想是不是因为缺少依赖

九师兄 4411

QT操作文件夹(创建、复制、重命名、移除)

头文件 #include <QDir> #include <QFileInfo> #include <QFile> 创建文件夹 //************************************ // 方法名称: CreateFolder // 概要: 创建文件夹 // 返回值: void // 参数: QString folderPath 文件夹路径 //************************************ void CreateF

WMT1520的博客 1万+

【异常】出现“‘git‘ 不是内部或外部命令,也不是可运行的程序”的错误

出现“‘git’ 不是内部或外部命令,也不是可运行的程序”的错误通常意味着 Git 没有被正确安装在你的系统上,或者其可执行文件的路径没有被添加到系统的环境变量中。

奶爸的编程之路,也就一周冷个三天 1389

Qt判断文件夹路径、文件是否存在不存在则创建

Qt判断文件夹/目录是否存在 Qt判断文件夹/目录是否存在,可以使用QDir类的exists方法来判断,在使用时需要包含头文件#include ,例如下面的代码: #include <QCoreApplication> #include <QDir> #include <QDebug> /// /// \brief 判断文件夹是否存在,不存在则创建 /// \param fullPath /// \return /// bool DirExist(QString ful

琅嬛福地 1万+

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

Qt QDir详解

c++使用QT的QDir:判断文件是否存在,读取文件,创建文件及及路径,遍历文件夹中的文件信息等,QDir中的函数使用说明

qq_30150579的博客 3950

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

QT检查文件夹是否存在及创建文件夹

如果你需要一个空文件夹,你可以循环,直到你得到一个空的文件夹。所以根据你的程序,你必须select哪个更适合。这种情况下,你将得到一个数字文件夹名称。,另一方面,如果path已经存在,时,如果path已经存在,则返回。你可以看到更多的Qt文档。

罗伯特祥的博客 2326

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

【Qt5】创建文件夹

//头文件 #include <QDir> //代码 "../path"为目录路径 QDir dir; dir.cd("../path"); //进入某文件夹 if(!dir.exists("文件夹名字"))//判断需要创建的文件夹是否存在 { dir.mkdir("文件夹名字"); //创建文件夹 }

RobotPlus 7305

通俗易懂玩Qt:QDir 创建文件夹

因为项目需求,需要创建文件夹来存储日志,然后在官网找了代码来使用,结果文件夹创建失败了,找了半天原因,最后发现是自己使用了相对路径造成的,这里特别提出来一下。后面检查逻辑的时候才反应过来,如果使用上面的方式来创建文件夹的话,会创建两次。中装载的是相对路径还是绝对路径,都能够在上级文件夹存在的情况下成功创建文件夹。学习分享,一起成长!以上为小编的经验分享,若存在不当之处,请批评指正!在网上找了半天,然后发现就只有这篇文章稍微有点用。,其他的文章没有太大的帮助,文章里面说了。

混子还在路上 2032

[Qt] [QDir] 创建文件夹和删除文件夹

[Qt] [QDir] 创建文件夹和删除文件夹

AaronLee的博客 3006

Qt 之QDir文件目录拷贝、创建、删除 (***)

Qt 之QDir文件目录拷贝、创建、删除 (***

ken2232的博客 1299
上一篇: Qt颜色对话框 QColorDialog
下一篇: Qt写入文件操作QFile
qiukapi
博客等级 码龄12年 51粉丝 93原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值