首页 > 解决方案 > 从控制台应用程序使用 QFileSystemWatcher

问题描述

我想从控制台应用程序中使用 QFileSystemWatcher,而我目前的方法没有收到任何被忽略的信号。谁能指出这个设置有什么问题?

static duk_ret_t automation_watch(duk_context *ctx)
{
    int argc = 0; char** argv = 0;
    QCoreApplication app(argc, argv);

    bool retval = false;
    QFileSystemWatcher *watcher = new QFileSystemWatcher(&app);
    qDebug() << QDir::current().absolutePath();
    watcher->addPath(QDir::current().absolutePath());
    retval = QObject::connect(watcher, &QFileSystemWatcher::fileChanged, [](const QString& a) {
        printf(a.toStdString().c_str());
        printf("\r\n");
        return 0;
    }); 
    assert(retval == true);

    retval = QObject::connect(watcher, &QFileSystemWatcher::directoryChanged , [](const QString& a) {
        printf(a.toStdString().c_str());
        printf("\r\n");
        return 0;
    });
    assert(retval == true);

    app.exec();
    return 0;
}

标签: c++qt

解决方案


推荐阅读