从控制台应用程序使用QFileSystemWatcher

时间:2018-08-03 10:24:35

标签: c++ qt

我想从控制台应用程序使用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;
}

0 个答案:

没有答案