File: main.cpp

package info (click to toggle)
dtkcore 5.7.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,728 kB
  • sloc: cpp: 22,021; ansic: 183; python: 68; xml: 58; makefile: 27; sh: 15
file content (48 lines) | stat: -rw-r--r-- 1,381 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "filesystem/dfilewatchermanager.h"
#include <QCoreApplication>
#include <QTemporaryFile>
#include <QDebug>
DCORE_USE_NAMESPACE

int main(int argc, char **argv)
{
    QCoreApplication app(argc, argv);
    DFileWatcherManager manager;
    QTemporaryFile tmpfile1;
    tmpfile1.open();
    QFile file1(tmpfile1.fileName());
    QTemporaryFile tmpfile2;
    tmpfile2.open();
    QFile file2(tmpfile2.fileName());

    manager.add(tmpfile1.fileName());
    manager.add(tmpfile2.fileName());

    QObject::connect(&manager, &Dtk::Core::DFileWatcherManager::fileModified, &app, [=](const QString value) {
        qDebug() << "文件发生变动:" << value;
    });

    QObject::connect(&manager, &Dtk::Core::DFileWatcherManager::fileDeleted, &app, [=](const QString value) {
        qDebug() << "文件被删除:" << value;
    });

    file1.open(QIODevice::WriteOnly | QIODevice::Text);
    file1.write("test");
    file1.flush();
    file1.close();

    file2.open(QIODevice::WriteOnly | QIODevice::Text);
    file2.write("test");
    file2.close();

    qDebug() << manager.watchedFiles();
    qDebug() << "---------------------------";
    app.processEvents();
    manager.removeAll();
    qDebug() << manager.watchedFiles();
    return app.exec();
}