| 1 |
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-3.0-or-later |
| 4 |
|
| 5 |
#include "filesystem/dfilewatchermanager.h" |
| 6 |
#include <QCoreApplication> |
| 7 |
#include <QTemporaryFile> |
| 8 |
#include <QDebug> |
| 9 |
DCORE_USE_NAMESPACE |
| 10 |
|
| 11 |
int main(int argc, char **argv) |
| 12 |
{ |
| 13 |
QCoreApplication app(argc, argv); |
| 14 |
DFileWatcherManager manager; |
| 15 |
QTemporaryFile tmpfile1; |
| 16 |
tmpfile1.open(); |
| 17 |
QFile file1(tmpfile1.fileName()); |
| 18 |
QTemporaryFile tmpfile2; |
| 19 |
tmpfile2.open(); |
| 20 |
QFile file2(tmpfile2.fileName()); |
| 21 |
|
| 22 |
manager.add(tmpfile1.fileName()); |
| 23 |
manager.add(tmpfile2.fileName()); |
| 24 |
|
| 25 |
QObject::connect(&manager, &Dtk::Core::DFileWatcherManager::fileModified, &app, [=](const QString value) { |
| 26 |
qDebug() << "文件发生变动:" << value; |
| 27 |
}); |
| 28 |
|
| 29 |
QObject::connect(&manager, &Dtk::Core::DFileWatcherManager::fileDeleted, &app, [=](const QString value) { |
| 30 |
qDebug() << "文件被删除:" << value; |
| 31 |
}); |
| 32 |
|
| 33 |
file1.open(QIODevice::WriteOnly | QIODevice::Text); |
| 34 |
file1.write("test"); |
| 35 |
file1.flush(); |
| 36 |
file1.close(); |
| 37 |
|
| 38 |
file2.open(QIODevice::WriteOnly | QIODevice::Text); |
| 39 |
file2.write("test"); |
| 40 |
file2.close(); |
| 41 |
|
| 42 |
qDebug() << manager.watchedFiles(); |
| 43 |
qDebug() << "---------------------------"; |
| 44 |
app.processEvents(); |
| 45 |
manager.removeAll(); |
| 46 |
qDebug() << manager.watchedFiles(); |
| 47 |
return app.exec(); |
| 48 |
} |