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) | 文件改变 |
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
{
if (!newFile.isEmpty())
{
cout << "New Files/Dirs added: " ;
foreach (QString file, newFile)
{
cout<<file<<endl;
}
}
if (!deleteFile.isEmpty())
{
cout << "Files/Dirs deleted: " ;
foreach(QString file, deleteFile)
{
cout<<file<<endl;
}
}
}
}
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
Constant | Value |
---|
QFileIconProvider::Computer | 0 |
QFileIconProvider::Desktop | 1 |
QFileIconProvider::Trashcan | 2 |
QFileIconProvider::Network | 3 |
QFileIconProvider::Drive | 4 |
QFileIconProvider::Folder | 5 |
QFileIconProvider::File | 6 |

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();