Qt文件和目录相关操作

1.相关说明

QCoreApplication类、QFile类、QDir、QTemporaryDir类、QTemporaryFile类、QFileSystemWatcher类的相关函数

2.相关界面

3.相关代码

#include "dialog.h"
#include "ui_dialog.h"
#include <QFileDialog>
#include <QTemporaryDir>
#include <QTemporaryFile>
#include <QFileSystemWatcher>

Dialog::Dialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::Dialog)
{
    ui->setupUi(this);
    fileWatcher = NULL;
}

Dialog::~Dialog()
{
    delete ui;
}

// 打开一个文件
void Dialog::on_btnOpenFile_clicked()
{
    QString curDir = QCoreApplication::applicationDirPath();
    QString aFile = QFileDialog::getOpenFileName(this, "打开一个文件", curDir, "(*.cpp *.h *.c);;(*.*)");
    ui->lineEditFile->setText(aFile);
}
// 打开一个目录
void Dialog::on_btnOpenDir_clicked()
{
    QString curDir = QCoreApplication::applicationDirPath();
    QString aDir = QFileDialog::getExistingDirectory(this, "选择一个目录", curDir);
    ui->lineEditDir->setText(aDir);
}
// 清除文本框
void Dialog::on_btnClear_clicked()
{
    ui->plainTextEdit->clear();
}

void Dialog::showBtnInfo(QObject *btn)
{
    QPushButton *theBtn = static_cast<QPushButton*>(btn);
    ui->plainTextEdit->appendPlainText(theBtn->text());
    ui->plainTextEdit->appendPlainText(theBtn->toolTip()+":");
}

// applicationDirPath()
void Dialog::on_btnApplicationDirPath_clicked()
{
    showBtnInfo(sender());
    QString str = QCoreApplication::applicationDirPath();
    ui->plainTextEdit->appendPlainText(str);
}
// applicationFilePath()
void Dialog::on_btnApplicationFilePath_clicked()
{
    showBtnInfo(sender());
    QString str = QCoreApplication::applicationFilePath();
    ui->plainTextEdit->appendPlainText(str);
}
// applicationName()
void Dialog::on_btnApplicationName_clicked()
{
    showBtnInfo(sender());
    // QCoreApplication::setApplicationName("My App");
    QString str = QCoreApplication::applicationName();
    ui->plainTextEdit->appendPlainText(str);
}
// setApplicationName(QString)
void Dialog::on_btnSetApplicationName_clicked()
{
    showBtnInfo(sender());
    QCoreApplication::setApplicationName("My App");
    QString str = QCoreApplication::applicationName();
    ui->plainTextEdit->appendPlainText(str);
}
// libraryPaths()
void Dialog::on_btnLibraryPaths_clicked()
{
    showBtnInfo(sender());
    QStringList paths = QCoreApplication::libraryPaths();
    for(auto &path : paths){
        ui->plainTextEdit->appendPlainText(path);
    }
}
// organizationName()
void Dialog::on_btnOrganiazationName_clicked()
{
    showBtnInfo(sender());
    QCoreApplication::setOrganizationName("My Organization");
    QString orgName = QCoreApplication::organizationName();
    ui->plainTextEdit->appendPlainText(orgName);
}
// exit()
void Dialog::on_btnExit_clicked()
{
    QCoreApplication::exit();
}
// QFile::copy
void Dialog::on_btnQFileCopy_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    QFileInfo fileInfo(sourceFile);
    QString newFile = fileInfo.path()+"/"+fileInfo.baseName()+"--副本."+fileInfo.suffix();
    QFile::copy(sourceFile, newFile);
    ui->plainTextEdit->appendPlainText("源文件:"+sourceFile);
    ui->plainTextEdit->appendPlainText("副本:"+newFile);
}
// QFile::exists
void Dialog::on_btnQFileExists_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    if(QFile::exists(sourceFile)){
        ui->plainTextEdit->appendPlainText(sourceFile + ":存在");
    } else {
        ui->plainTextEdit->appendPlainText(sourceFile + ":不存在");
    }

}
// QFile::remove
void Dialog::on_btnRemove_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    if(QFile::remove(sourceFile)){
        ui->plainTextEdit->appendPlainText("remove "+sourceFile+" 成功");
    } else {
        ui->plainTextEdit->appendPlainText("remove "+sourceFile+" 失败");
    }
}
// QFile::rename
void Dialog::on_btnQFileRename_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    QFileInfo fileInfo(sourceFile);
    QString newFile = fileInfo.path()+"/"+fileInfo.baseName()+"--新名称."+fileInfo.suffix();
    if(QFile::rename(sourceFile, newFile)){
        ui->plainTextEdit->appendPlainText("旧名称:"+sourceFile);
        ui->plainTextEdit->appendPlainText("新名称:"+newFile);
    } else {
        ui->plainTextEdit->appendPlainText("修改 "+sourceFile+" 失败");
    }
}
// QFile::moveToTrash
void Dialog::on_btnQFileMoveToTrash_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    if(QFile::exists(sourceFile) && QFile::moveToTrash(sourceFile)){
        ui->plainTextEdit->appendPlainText("删除文件到垃圾箱:"+sourceFile);
    } else {
        ui->plainTextEdit->appendPlainText("文件不存在");
    }
}
// file.copy
void Dialog::on_btnCopy_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    QFileInfo fileInfo(sourceFile);
    QString newFile = fileInfo.path()+"/"+fileInfo.baseName()+"--副本."+fileInfo.suffix();
    QFile file(sourceFile);
    // QFile::copy(sourceFile, newFile);
    if(file.copy(newFile)){
        ui->plainTextEdit->appendPlainText("源文件:"+sourceFile);
        ui->plainTextEdit->appendPlainText("副本:"+newFile);
    } else {
        ui->plainTextEdit->appendPlainText("复制文件失败:"+sourceFile);
    }

}
// file.exists
void Dialog::on_btnExists_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    QFile file(sourceFile);
    if(file.exists()){
        ui->plainTextEdit->appendPlainText(sourceFile + ":存在");
    } else {
        ui->plainTextEdit->appendPlainText(sourceFile + ":不存在");
    }
}
// file.remove
void Dialog::on_btnRemove_2_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    QFile file(sourceFile);
    if(file.remove()){
        ui->plainTextEdit->appendPlainText("remove "+sourceFile+" 成功");
    } else {
        ui->plainTextEdit->appendPlainText("remove "+sourceFile+" 失败");
    }
}
// file.rename
void Dialog::on_btnRename_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    QFileInfo fileInfo(sourceFile);
    QString newFile = fileInfo.path()+"/"+fileInfo.baseName()+"--新名称."+fileInfo.suffix();
    QFile file(sourceFile);
    if(file.rename(newFile)){
        ui->plainTextEdit->appendPlainText("旧名称:"+sourceFile);
        ui->plainTextEdit->appendPlainText("新名称:"+newFile);
    } else {
        ui->plainTextEdit->appendPlainText("修改 "+sourceFile+" 失败");
    }
}
// file.moveToTrash
void Dialog::on_btnMoveToTrash_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    QFile file(sourceFile);
    if(file.exists() && file.moveToTrash()){
        ui->plainTextEdit->appendPlainText("删除文件到垃圾箱:"+sourceFile);
    } else {
        ui->plainTextEdit->appendPlainText("文件不存在");
    }
}
// absoluteFilePath()
void Dialog::on_btnAbsoluteFilePath_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    QFileInfo fileInfo(sourceFile);
    QString absfilePath = fileInfo.absoluteFilePath();
    ui->plainTextEdit->appendPlainText(absfilePath);
}
// absolutePath()
void Dialog::on_btnAbsolutePath_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    QFileInfo fileInfo(sourceFile);
    QString absfilePath = fileInfo.absolutePath();
    ui->plainTextEdit->appendPlainText(absfilePath);
}
// fileInfo.fileName()
void Dialog::on_btnFileName_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    QFileInfo fileInfo(sourceFile);
    QString fileName = fileInfo.fileName();
    ui->plainTextEdit->appendPlainText(fileName);
}
// fileInfo.filePath()
void Dialog::on_btnFilePath_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    QFileInfo fileInfo(sourceFile);
    QString filePath = fileInfo.filePath();
    ui->plainTextEdit->appendPlainText(filePath);
}
// fileInfo.size()
void Dialog::on_btnSize_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    QFileInfo fileInfo(sourceFile);
    QString fileSize = QString::number(fileInfo.size());
    ui->plainTextEdit->appendPlainText(fileSize+"Bytes");
}
// fileInfo.path()
void Dialog::on_btnPath_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    QFileInfo fileInfo(sourceFile);
    QString path = fileInfo.path();
    ui->plainTextEdit->appendPlainText(path);
}
// fileInfo.baseName()
void Dialog::on_btnBaseName_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    QFileInfo fileInfo(sourceFile);
    QString baseName = fileInfo.baseName();
    ui->plainTextEdit->appendPlainText(baseName);
}
// fileInfo.completeBaseName()
void Dialog::on_btnCompleteBaseName_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    QFileInfo fileInfo(sourceFile);
    QString completeBaseName = fileInfo.completeBaseName();
    ui->plainTextEdit->appendPlainText(completeBaseName);
}
// fileInfo.suffix()
void Dialog::on_btnSuffix_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    QFileInfo fileInfo(sourceFile);
    QString suffix = fileInfo.suffix();
    ui->plainTextEdit->appendPlainText(suffix);
}
// fileInfo.completeSuffix()
void Dialog::on_btnCompleteSuffix_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    QFileInfo fileInfo(sourceFile);
    QString completeSuffix = fileInfo.completeSuffix();
    ui->plainTextEdit->appendPlainText(completeSuffix);
}
// fileInfo.isDir()
void Dialog::on_btnIsDir_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    QFileInfo fileInfo(sourceFile);
    if(fileInfo.isDir()){
        ui->plainTextEdit->appendPlainText("目录");
    } else {
        ui->plainTextEdit->appendPlainText("非目录");
    }
}
// fileInfo.isFile()
void Dialog::on_btnIsFile_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    QFileInfo fileInfo(sourceFile);
    if(fileInfo.isFile()){
        ui->plainTextEdit->appendPlainText("文件");
    } else {
        ui->plainTextEdit->appendPlainText("非文件");
    }
}
// fileInfo.isExecutable()
void Dialog::on_btnIsExecutable_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    QFileInfo fileInfo(sourceFile);
    if(fileInfo.isExecutable()){
        ui->plainTextEdit->appendPlainText("执行文件");
    } else {
        ui->plainTextEdit->appendPlainText("非执行文件");
    }
}
// fileInfo.birthTime()
void Dialog::on_btnBirthTime_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    QFileInfo fileInfo(sourceFile);
    if(fileInfo.exists()){
        ui->plainTextEdit->appendPlainText("创建时间:"+fileInfo.birthTime().toString("yyyy-MM-dd hh:mm:ss"));
    }
}
// fileInfo.lastModified()
void Dialog::on_btnLastModified_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    QFileInfo fileInfo(sourceFile);
    if(fileInfo.exists()){
        ui->plainTextEdit->appendPlainText("最后修改时间:"+fileInfo.lastModified().toString("yyyy-MM-dd hh:mm:ss"));
    }
}
// fileInfo.lastRead()
void Dialog::on_btnLastRead_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    QFileInfo fileInfo(sourceFile);
    if(fileInfo.exists()){
        ui->plainTextEdit->appendPlainText("最后读取时间:"+fileInfo.lastRead().toString("yyyy-MM-dd hh:mm:ss"));
    }
}
// QFileInfo::exists(sourceFile)
void Dialog::on_btnStaticExists_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    if(QFileInfo::exists(sourceFile)){
        ui->plainTextEdit->appendPlainText("文件存在");
    } else {
        ui->plainTextEdit->appendPlainText("文件不存在");
    }
}
// fileInfo.exists()
void Dialog::on_btnDynamicExists_clicked()
{
    showBtnInfo(sender());
    QString sourceFile = ui->lineEditFile->text();
    QFileInfo fileInfo(sourceFile);
    if(fileInfo.exists()){
        ui->plainTextEdit->appendPlainText("文件存在");
    } else {
        ui->plainTextEdit->appendPlainText("文件不存在");
    }
}
// QDir::tempPath()
void Dialog::on_btnTempPath_clicked()
{
    showBtnInfo(sender());
    ui->plainTextEdit->appendPlainText("tempPath:"+QDir::tempPath());
}
// QDir::rootPath()
void Dialog::on_btnRootPath_clicked()
{
    showBtnInfo(sender());
    ui->plainTextEdit->appendPlainText("rootPath:"+QDir::rootPath());
}
// QDir::homePath()
void Dialog::on_btnHomePath_clicked()
{
    showBtnInfo(sender());
    ui->plainTextEdit->appendPlainText("homePath:"+QDir::homePath());
}
// QDir::drives()
void Dialog::on_btnDrives_clicked()
{
    showBtnInfo(sender());
    QFileInfoList filelist = QDir::drives();
    for(auto &fileInfo : filelist){
        ui->plainTextEdit->appendPlainText(fileInfo.path());
    }
}
// QDir::currentPath()
void Dialog::on_btnCurrentPath_clicked()
{
    showBtnInfo(sender());
    ui->plainTextEdit->appendPlainText("currentPath:"+QDir::currentPath());
}

// QDir::setCurrent(ui->lineEditDir->text())
void Dialog::on_btnSetCurrent_clicked()
{
    showBtnInfo(sender());
    QDir::setCurrent(ui->lineEditDir->text());
    ui->plainTextEdit->appendPlainText("currentPath:"+QDir::currentPath());
}
// dir.mkdir(subDir)
void Dialog::on_btnMkdir_clicked()
{
    showBtnInfo(sender());
    QString subDir = "subdir";
    QDir dir(ui->lineEditDir->text());
    if(dir.mkdir(subDir)){
        ui->plainTextEdit->appendPlainText("创建成功:"+subDir);
    } else {
        ui->plainTextEdit->appendPlainText("创建失败:"+subDir);
    }
}
// dir.rmdir(subDir)
void Dialog::on_btnRmdir_clicked()
{
    showBtnInfo(sender());
    QString subDir = "subdir";
    QDir dir(ui->lineEditDir->text());
    if(dir.rmdir(subDir)){
        ui->plainTextEdit->appendPlainText("删除成功:"+subDir);
    } else {
        ui->plainTextEdit->appendPlainText("删除失败:"+subDir);
    }
}
// dir.remove(fileName)
void Dialog::on_btnRemove_3_clicked()
{
    showBtnInfo(sender());
    QString fileName = ui->lineEditFile->text();
    QDir dir(ui->lineEditDir->text());
    if(dir.remove(fileName)){
        ui->plainTextEdit->appendPlainText("删除成功:"+fileName);
    } else {
        ui->plainTextEdit->appendPlainText("删除失败:"+fileName);
    }
}
// dir.rename(fileName, newFile)
void Dialog::on_btnDirRename_clicked()
{
    showBtnInfo(sender());
    QString fileName = ui->lineEditFile->text();
    QFileInfo fileInfo(fileName);
    QDir dir(ui->lineEditDir->text());
    QString newFile = fileInfo.path()+"/"+fileInfo.baseName()+".XYZ";
    if(dir.rename(fileName, newFile)){
        ui->plainTextEdit->appendPlainText("源文件:"+fileName);
        ui->plainTextEdit->appendPlainText("修改后的文件:"+newFile);
    } else {
        ui->plainTextEdit->appendPlainText("修改失败");
    }
}
// lastDir.setPath(aDir)
void Dialog::on_btnSetPath_clicked()
{
    showBtnInfo(sender());
    QString curDir = QDir::currentPath();
    QDir lastDir(curDir);
    ui->plainTextEdit->appendPlainText("当前目录:"+lastDir.absolutePath());
    QString aDir = QFileDialog::getExistingDirectory(this, "选择一个目录",curDir);
    if(aDir.isEmpty()){
        return;
    }
    ui->lineEditDir->setText(aDir);
    lastDir.setPath(aDir);
    ui->plainTextEdit->appendPlainText("选择后的目录:"+lastDir.absolutePath());
}
// aDir.removeRecursively()
void Dialog::on_btnRemoveRecursively_clicked()
{
    showBtnInfo(sender());
    QDir aDir(ui->lineEditDir->text());
    if(aDir.removeRecursively()){
        ui->plainTextEdit->appendPlainText("递归删除成功");
    } else {
        ui->plainTextEdit->appendPlainText("递归删除失败");
    }
}
// aDir.absoluteFilePath(ui->lineEditFile->text())
void Dialog::on_btnAbsoluteFilePath_2_clicked()
{
    showBtnInfo(sender());
    QDir aDir(ui->lineEditDir->text());
    QString str = aDir.absoluteFilePath(ui->lineEditFile->text());
    ui->plainTextEdit->appendPlainText(str);
}
// aDir.absolutePath()
void Dialog::on_btnDirAbsolutePath_clicked()
{
    showBtnInfo(sender());
    QDir aDir(ui->lineEditDir->text());
    ui->plainTextEdit->appendPlainText(aDir.absolutePath());
}
// aDir.canonicalPath()
void Dialog::on_btnCanonicalPath_clicked()
{
    showBtnInfo(sender());
    QDir aDir(ui->lineEditDir->text());
    ui->plainTextEdit->appendPlainText(aDir.canonicalPath());
}
// aDir.filePath(ui->lineEditFile->text())
void Dialog::on_btnDirFilePath_clicked()
{
    showBtnInfo(sender());
    QDir aDir(ui->lineEditDir->text());
    QString filePath = aDir.filePath(ui->lineEditFile->text());
    ui->plainTextEdit->appendPlainText(filePath);
}
// aDir.path()
void Dialog::on_btnDirPath_clicked()
{
    showBtnInfo(sender());
    QDir aDir(ui->lineEditDir->text());
    ui->plainTextEdit->appendPlainText(aDir.path());
}
// aDir.dirName()
void Dialog::on_btnDirName_clicked()
{
    showBtnInfo(sender());
    QDir aDir(ui->lineEditDir->text());
    ui->plainTextEdit->appendPlainText(aDir.dirName());
}
// aDir.exists()
void Dialog::on_btnDirExists_clicked()
{
    showBtnInfo(sender());
    QDir aDir(ui->lineEditDir->text());
    if(aDir.exists()){
        ui->plainTextEdit->appendPlainText("存在:"+aDir.dirName());
    } else {
        ui->plainTextEdit->appendPlainText("不存在:"+aDir.dirName());
    }

}
// aDir.isEmpty()
void Dialog::on_btnDirIsEmpty_clicked()
{
    showBtnInfo(sender());
    QDir aDir(ui->lineEditDir->text());
    if(aDir.isEmpty()){
        ui->plainTextEdit->appendPlainText("空文件夹:"+aDir.dirName());
    } else {
        ui->plainTextEdit->appendPlainText("非空文件夹:"+aDir.dirName());
    }
}
// aDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)
void Dialog::on_btnDirEntryList_clicked()
{
    showBtnInfo(sender());
    QDir aDir(ui->lineEditDir->text());
    QStringList strList = aDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
    ui->plainTextEdit->appendPlainText(aDir.dirName()+"目录下的所有目录:");
    for(QString &dir : strList){
        ui->plainTextEdit->appendPlainText(dir);
    }
}
// aDir.entryList(QDir::Files)
void Dialog::on_btnFileEntryList_clicked()
{
    showBtnInfo(sender());
    QDir aDir(ui->lineEditDir->text());
    QStringList strList = aDir.entryList(QDir::Files);
    ui->plainTextEdit->appendPlainText(aDir.dirName()+"目录下的所有文件:");
    for(QString &dir : strList){
        ui->plainTextEdit->appendPlainText(dir);
    }
}
// 1.在系统临时目录下创建临时文件夹
void Dialog::on_btnCreateTmpDir_clicked()
{
    showBtnInfo(sender());
    ui->plainTextEdit->appendPlainText("QDir::tempPath()="+QDir::tempPath());
    QTemporaryDir dir;
    dir.setAutoRemove(true);
    ui->plainTextEdit->appendPlainText(dir.path());
}
// 1.在系统临时目录下创建临时文件
void Dialog::on_btnCreateTmpFile_clicked()
{
    showBtnInfo(sender());
    ui->plainTextEdit->appendPlainText("QDir::tempPath()="+QDir::tempPath());
    QTemporaryFile aFile;
    aFile.setAutoRemove(true);
    aFile.open();
    ui->plainTextEdit->appendPlainText(aFile.fileName());
    aFile.close();
}
// 2.在指定目录下创建临时文件夹
void Dialog::on_btnCreateTmpDir_2_clicked()
{
    showBtnInfo(sender());
    QString specDir = ui->lineEditDir->text();
    ui->plainTextEdit->appendPlainText("指定目录="+specDir);
    QTemporaryDir dir(specDir + "/TempDir_XXX");
    dir.setAutoRemove(false);
    ui->plainTextEdit->appendPlainText(dir.path());
}
// 2.在指定目录下创建临时文件
void Dialog::on_btnCreateTmpFile_2_clicked()
{
    showBtnInfo(sender());
    QString specDir = ui->lineEditDir->text();
    ui->plainTextEdit->appendPlainText("指定目录="+specDir);
    QTemporaryFile aFile(specDir+"/TempFile_XXX");
    aFile.setAutoRemove(false);
    aFile.open();
    ui->plainTextEdit->appendPlainText(aFile.fileName());
    aFile.close();
}
// 3.在当前目录下创建临时文件夹
void Dialog::on_btnCreateCurTmpDir_clicked()
{
    showBtnInfo(sender());
    ui->plainTextEdit->appendPlainText("当前路径="+QDir::currentPath());
    QTemporaryDir dir("SubDir_XXX");
    dir.setAutoRemove(false);
    ui->plainTextEdit->appendPlainText(dir.path());
}
// 3.在当前目录下创建临时文件
void Dialog::on_btnCreateCurTmpFile_clicked()
{
    showBtnInfo(sender());
    ui->plainTextEdit->appendPlainText("当前路径="+QDir::currentPath());
    QTemporaryFile aFile("CurTempFile_XXX.temp");
    aFile.setAutoRemove(false);
    aFile.open();
    ui->plainTextEdit->appendPlainText(aFile.fileName());
    aFile.close();
}
void Dialog::do_directoryChanged(const QString &path)
{
    ui->plainTextEdit->appendPlainText(path + "目录发生了变化");
}

void Dialog::do_fileChanged(const QString &path)
{
    ui->plainTextEdit->appendPlainText(path+"文件发生了变化");
}
// addPath()并开始监视
void Dialog::on_btnAddPathWatcher_clicked()
{
    showBtnInfo(sender());
    if(fileWatcher == NULL){
        fileWatcher = new QFileSystemWatcher(this);
    }
    fileWatcher->addPath(ui->lineEditDir->text());
    fileWatcher->addPath(ui->lineEditFile->text());
    connect(fileWatcher, &QFileSystemWatcher::directoryChanged, this, &Dialog::do_directoryChanged);
    connect(fileWatcher, &QFileSystemWatcher::fileChanged, this, &Dialog::do_fileChanged);
}
// removePath()并停止监视
void Dialog::on_btnRemovePathWatcher_clicked()
{
    showBtnInfo(sender());
    fileWatcher->removePath(ui->lineEditDir->text());
    fileWatcher->removePath(ui->lineEditFile->text());
    disconnect(fileWatcher);
}
// directories()
void Dialog::on_btnDirectories_clicked()
{
    showBtnInfo(sender());
    for(auto &item : fileWatcher->directories()){
        ui->plainTextEdit->appendPlainText(item);
    }
}
// files()
void Dialog::on_btnFiles_clicked()
{
    showBtnInfo(sender());
    for(QString &item : fileWatcher->files()){
        ui->plainTextEdit->appendPlainText(item);
    }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/336535.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【JavaEE】网络原理:网络中的一些基本概念

目录 1. 网络通信基础 1.1 IP地址 1.2 端口号 1.3 认识协议 1.4 五元组 1.5 协议分层 什么是协议分层 分层的作用 OSI七层模型 TCP/IP五层&#xff08;或四层&#xff09;模型 网络设备所在分层 网络分层对应 封装和分用 1. 网络通信基础 1.1 IP地址 概念:IP地址…

AIGC语言大模型涌现能力是幻觉吗?

Look&#xff01;&#x1f440;我们的大模型商业化落地产品&#x1f4d6;更多AI资讯请&#x1f449;&#x1f3fe;关注Free三天集训营助教在线为您火热答疑&#x1f469;&#x1f3fc;‍&#x1f3eb; 在自然界中&#xff0c;涌现现象无处不在&#xff0c;从鸟群的和谐飞翔到生…

【C++】unordered_map,unordered_set模拟实现

unordered_map&#xff0c;unordered_set模拟实现 插入普通迭代器const迭代器unordered_map的[ ]接口实现查找修改哈希桶完整代码unordered_map完整代码unordered_set完整代码 喜欢的点赞&#xff0c;收藏&#xff0c;关注一下把&#xff01; 上一篇文章我们把unordered_map和u…

基于JavaWeb+SSM+Vue基于微信小程序的网上商城系统的设计和实现

基于JavaWebSSMVue基于微信小程序的网上商城系统的设计和实现 滑到文末获取源码Lun文目录前言主要技术系统设计功能截图订阅经典源码专栏Java项目精品实战案例《500套》 源码获取 滑到文末获取源码 Lun文目录 目录 1系统概述 1 1.1 研究背景 1 1.2研究目的 1 1.3系统设计思想…

深度剖析跨境商城源码架构,助你把握行业动向

跨境电商作为当今电商行业的热点&#xff0c;其源码架构备受关注。作为专家&#xff0c;我将深度剖析跨境商城源码架构&#xff0c;帮助你把握行业动向。 跨境商城源码架构的基本组成 跨境商城源码架构一般包括前台系统、后台管理系统、数据管理系统和安全系统四大模块。前台…

LabVIEW振动数据采集与分析系统

在这个项目中&#xff0c; LabVIEW软件配合精确的硬件组件&#xff0c;以实现高效的振动数据采集和复杂信号分析。硬件方面&#xff0c;系统采用了PCB振动加速度传感器的高灵敏度传感器&#xff0c;以及NI9234型号的数据采集卡&#xff0c;确保了数据采集的高精度和可靠性。软件…

实用干货:最全的Loading动画合集网站!复制即用

大家好&#xff0c;我是大澈&#xff01; 本文约1000字&#xff0c;整篇阅读大约需要2分钟。 感谢关注微信公众号&#xff1a;“程序员大澈”&#xff0c;免费领取"面试礼包"一份&#xff0c;然后免费加入问答群&#xff0c;从此让解决问题的你不再孤单&#xff01…

OpenHarmony 应用开发入门 (二、应用程序包结构理解及Ability的跳转,与Android的对比)

在进行应用开发前&#xff0c;对程序的目录及包结构的理解是有必要的。如果之前有过android开发经验的&#xff0c;会发现OpenHarmony的应用开发也很简单&#xff0c;有很多概念是相似的。下面对比android分析总结下鸿蒙的应用程序包结构&#xff0c;以及鸿蒙对比android的诸多…

Dobbo --- HelloWorld项目搭建

Dobbo-HelloWorld 1. demo -- spring方式集成1.1 实现步骤 2. demo -- springboot方式集成2.1 实现provider2.2 实现consumer2.3 项目测试 1. demo – spring方式集成 dubbo官方文档 提供一个可被调用的接口 提供方&#xff1a;实现接口的方法逻辑&#xff0c;启动应用程序&a…

python实操之网络爬虫介绍

一、什么是网络爬虫 网络爬虫&#xff0c;也可以叫做网络数据采集更容易理解。它是指通过编程向网络服务器&#xff08;web&#xff09;请求数据&#xff08;HTML表单&#xff09;&#xff0c;然后解析HTML&#xff0c;提取出自己想要的数据。 它包括了根据url获取HTML数据、解…

介绍几个免费的国内chatgpt网站

概述&#xff1a;水点文章。 第一&#xff1a;chataa网站 chataa (chat778.com) 进去之后注册一下&#xff0c;即可免费使用。 第二&#xff1a;AlchatOS网站 AIchatOS 第三&#xff1a;ChatGPT在线聊天 ChatGPT在线聊天 (zxf7460.cn) 第四&#xff1a;说我真帅&#xff0…

【Python】--- 基础语法(1)

目录 1.变量和表达式2.变量和类型2.1变量是什么2.2变量的语法2.3变量的类型2.3.1整数2.3.2浮点数&#xff08;小数&#xff09;2.3.3字符串2.3.4布尔2.3.5其他 2.4为什么要有这么多类型2.5动态类型特征 3.注释3.1注释的语法3.2注释的规范 结语 1.变量和表达式 对python的学习就…

麒麟V10挂载iso,配置yum源

本文介绍yum 如何挂载本地镜像源 1) 拷贝镜像到本地 2) 执行以下命令&#xff1a; # mount -o loop 镜像路径及镜像名字 /mnt&#xff08;或 media&#xff09; 挂载前 挂载后 3) 进入/etc/yum.repos.d&#xff08;yum.repos.d 是一个目录&#xff0c;该目录是分析 RPM 软件…

kafka(一)——简介

简介 Kafka 是一种分布式、支持分区、多副本的消息中间件&#xff0c;支持发布-订阅模式&#xff0c;多用于实时处理大量数据缓存的场景&#xff0c;类似于一个“缓存池”。 架构 Producer&#xff1a;消息生产者&#xff1b;Consumer&#xff1a;消息消费者&#xff1b;Brok…

【Go】rune和byte类型的认识与使用

【Go】rune和byte类型的认识与使用 大家好 我是寸铁&#x1f44a; 总结了一篇rune和byte类型的认识与使用的文章✨ 喜欢的小伙伴可以点点关注 &#x1f49d; byte和rune类型定义 byte,占用1个字节&#xff0c;共8个比特位&#xff0c;所以它实际上和uint8没什么本质区别,它表示…

Windows11开启SSH服务

文章目录 环境背景安装SSH服务配置SSH服务启动/停止SSH服务登录接下来参考 环境 Windows 11 家庭中文版 背景 在我的Windows电脑上&#xff0c;有些网站无法直接访问&#xff0c;所以需要通过Mac来代理。为此&#xff0c;需要创建一个位于Windows和Mac之间的SSH tunnel。 在…

【C++】vector容器接口要点的补充

接口缩容 在VS编译器的模式下&#xff0c;类似于erase和insert接口的函数通常会进行缩容&#xff0c;因此&#xff0c;insert和erase行参中的迭代器可能会失效。下图中以erase为例&#xff1a; 代码如下&#xff1a; #include <iostream> #include <vector> #inclu…

如何本地部署虚VideoReTalking

环境&#xff1a; Win10专业版 VideoReTalking 问题描述&#xff1a; 如何本地部署虚VideoReTalking 解决方案&#xff1a; VideoReTalking是一个强大的开源AI对嘴型工具&#xff0c;它是我目前使用过的AI对嘴型工具中效果最好的一个&#xff01;它是由西安电子科技大学、…

MATLAB聚类工具箱

本文借鉴了数学建模清风老师的课件与思路&#xff0c;可以点击查看链接查看清风老师视频讲解&#xff1a;【1】MATLAB聚类工具箱&#xff1a;提前预览工具箱的核心功能_哔哩哔哩_bilibili 关于工具箱的获取&#xff0c;在数学建模学习交流公众号里发送&#xff1a; 567891 %% …

idea 安装免费Ai工具 codeium

目录 概述 ide安装 使用 chat问答 自动写代码 除此外小功能 概述 这已经是我目前用的最好免费的Ai工具了&#xff0c;当然你要是有钱最好还是用点花钱的&#xff0c;比如copilot&#xff0c;他可以在idea全家桶包括vs&#xff0c;还有c/c的vs上运行&#xff0c;还贼强&am…