qt

xiaoxiao2022-06-11  21

qt_文件运用,调用桌面

QFileSystemWatcher

函数描述bool addPath(const QString &path)添加一个pathQStringList addPaths(const QStringList &paths)添加一个路径QStringList directories() const监控目录的顺序bool removePath(const QString &path)删除QStringList removePaths(const QStringList &paths)

sinals:

函数描述void directoryChanged(const QString &path)目录改变void fileChanged(const QString &path)文件改变 /* * 文件监视QFileSystemWatcher * addpath removepath * directoryChanged fileChanged * 监视整个路径,那就可以前后做比较,找出哪个文件发生了什么,最主要是qset的魅力 * * */ FileIo::FileIo(QWidget *parent) : QWidget(parent) { QTextStream cout(stdout); setWindowTitle("file system"); QFileSystemWatcher *pfile_watch=new QFileSystemWatcher; path_str="E:/"; QDir dir(path_str); pfile_watch->addPath(path_str); currentDirSet=QSet<QString>::fromList(dir.entryList(QDir::Dirs|QDir::Files)); connect(pfile_watch,SIGNAL(directoryChanged(QString)),this,SLOT(direchange(QString))); } void FileIo::direchange(QString path) { QTextStream cout(stdout); QDir dir(path_str); QSet<QString> newDirSet=QSet<QString>::fromList(dir.entryList(QDir::Dirs|QDir::Files)); QStringList newFile = (newDirSet - currentDirSet).toList(); // 添加了文件 QStringList deleteFile = (currentDirSet - newDirSet).toList(); // 文件已被移除 currentDirSet=newDirSet; //更新储存的目录内容 if (!newFile.isEmpty() && !deleteFile.isEmpty()) { // 文件/目录重命名 if ((newFile.count() == 1) && (deleteFile.count() == 1)) { cout << QString("File Renamed from %1 to %2").arg(deleteFile.first()).arg(newFile.first())<<endl; } } else { // 添加新文件/目录至Dir if (!newFile.isEmpty()) { cout << "New Files/Dirs added: " ; foreach (QString file, newFile) { // 处理操作每个新文件.... cout<<file<<endl; } } // 从Dir中删除文件/目录 if (!deleteFile.isEmpty()) { cout << "Files/Dirs deleted: " ; foreach(QString file, deleteFile) { // 处理操作每个被删除的文件.... cout<<file<<endl; } } } } //源码见上传资源_文件目录监视https://download.csdn.net/download/qq_33564134/10618873

QDesktopServices

函数描述bool openUrl(const QUrl &url)打开一个urlvoid setUrlHandler(const QString &scheme, QObject *receiver, const char *method)定制.但是不会…void unsetUrlHandler(const QString &scheme)

QFileIconProvider

enum QFileIconProvider::IconType

ConstantValueQFileIconProvider::Computer0QFileIconProvider::Desktop1QFileIconProvider::Trashcan2QFileIconProvider::Network3QFileIconProvider::Drive4QFileIconProvider::Folder5QFileIconProvider::File6

/* * 两个途径获取文件的icon * pfileico->icon((QFileIconProvider::IconType)1) * pfileico->icon(info) */ FileIo::FileIo(QWidget *parent) : QWidget(parent) { setWindowTitle("file system"); QFileInfo info("E:/1.txt"); QListWidgetItem *pItem = new QListWidgetItem; QListWidget *list_widget=new QListWidget(this); QFileIconProvider *pfileico=new QFileIconProvider; list_widget->setFixedSize(400,400); list_widget->setIconSize(QSize(200,200)); pItem->setIcon(pfileico->icon((QFileIconProvider::IconType)1)); pItem->setText("电脑"); list_widget->addItem(pItem); pItem=new QListWidgetItem; pItem->setIcon(pfileico->icon(info)); pItem->setText("文本文件"); list_widget->addItem(pItem); }

QCryptographicHash加密

QByteArray byteArray; byteArray.append("password"); QByteArray hash = QCryptographicHash::hash(byteArray, QCryptographicHash::Md5); QString strMD5 = hash.toHex();
转载请注明原文地址: https://www.6miu.com/read-4931886.html

最新回复(0)