I am creating a very simple C ++ QT console application from the example given here when the stack overflows.
How to use QFileSystemWatcher to track folder changes
The code exactly matches the code in this application, and I am developing with Qt UI, Qt Creator with MinGW 32bit. I chose the console application from the projects that I could choose, since I do not need a graphical user interface. After the application has finished loading, the application displays the error message "WARNING: QApplication was not created in the main () thread" and then does nothing.
I tried to debug the application, but don't get breakpoint hits, I don't think that debugging works in the editor.
I quickly switched and changed QApplication to QCoreApplication when I develop a console application, but get the same error message.
filesystemreceiver.h
#ifndef FILESYSTEMRECEIVER_H #define FILESYSTEMRECEIVER_H #include <iostream> using namespace std; #include <QtCore/QApplication> #include <QtCore/QFileSystemWatcher> #include <QtCore/QDebug> #include <QtWidgets/QWidget> #include <QtWidgets/QMessageBox> class MyClass : public QWidget { Q_OBJECT public: MyClass(QWidget* parent=0) :QWidget(parent){} ~MyClass() {} public slots: void showModified(const QString& str) { Q_UNUSED(str) cout << "A message has been received!" << endl; //QMessageBox::information(this,"Directory Modified", "Your Directory is modified"); } }; #endif // FILESYSTEMRECEIVER_H
main.cpp
#include <iostream> using namespace std; #include <QtCore/QApplication> #include <QtCore/QFileSystemWatcher> #include <QtCore/QDebug> #include <QtWidgets/QWidget> #include <QtWidgets/QMessageBox> #include "fileSystemReceiver.h" int main(int argc, char* argv[]) { QApplication app(argc, argv); QFileSystemWatcher watcher; watcher.addPath("C:/QtTest"); QStringList directoryList = watcher.directories(); Q_FOREACH(QString directory, directoryList) qDebug() << "Directory name" << directory <<"\n"; MyClass* mc = new MyClass; QObject::connect(&watcher, SIGNAL(directoryChanged(QString)), mc, SLOT(showModified(QString))); return app.exec(); }
My pro file is as follows:
QT += core QT += widgets QT -= gui TARGET = fsw CONFIG += console CONFIG -= app_bundle TEMPLATE = app HEADERS += fileSystemReceiver.h SOURCES += \ main.cpp
source share