qt_文件运用,调用桌面

qt_文件运用,调用桌面

QFileSystemWatcher
函数描述
bool addPath(const QString &path)添加一个path
QStringList 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)打开一个url
void setUrlHandler(const QString &scheme, QObject *receiver, const char *method)定制.但是不会…
void unsetUrlHandler(const QString &scheme)
QFileIconProvider

enum QFileIconProvider::IconType

ConstantValue
QFileIconProvider::Computer0
QFileIconProvider::Desktop1
QFileIconProvider::Trashcan2
QFileIconProvider::Network3
QFileIconProvider::Drive4
QFileIconProvider::Folder5
QFileIconProvider::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.cnblogs.com/zylg/p/9831870.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值