Qt console application “WARNING: QApplication was not created in the main() thread”

后端 未结 1 903
情书的邮戳
情书的邮戳 2021-01-24 05:58

I\'m creating a very simple C++ QT console application from an example given here on stack overflow.

How to use QFileSystemWatcher to monitor a folder for change

相关标签:
1条回答
  • 2021-01-24 06:25

    You have had several issues ongoing in your project:

    • QCoreApplication in a program that is supposed to show a QWidget

    • Calling the main.cpp source file main.moc. That indicates that you do not quite understand how moc works and what it is about.

    • cout in a Qt program as opposed to QTextStream or qDebug().

    • Q_FOREACH in a source code not reused by other application, and hence no collision could normally occur. You should use "foreach" simply.

    • You are not using const reference for the string while iterating with the foreach even though you seem to be only reading it, not modifying.

    • You have hard coded path here instead of a const string in a well separated place: watcher.addPath("C:/QtTest");

    • You are adding widgets to the CONFIG variable, but you remove gui.

    • You are adding `core to the CONFIG variable when that is in there by default.

    • You include #include <QtWidgets/QFoo> instead of #include <QFoo> to keep the option of building with Qt 4, and in general with clearly buildsystem include paths.

    • You are adding CONFIG += console for a non-console based application.

    • You are adding CONFIG -= app_bundle for a non-console based application.

    • You are using back-slash for the SOURCES variable, but not for the HEADERS. This is inconsitent.

    • You create a MyClass instance on the heap as opposed to the stack to make it simpler for you as it is already properly guarded by the event loop to remain valid for the intended scope.

    On top of all that, your issue seems to be with qDebug() based on the comment discussion. You should follow the document below how to set up QtCreator for debugging properly.

    Setting Up Debugger

    0 讨论(0)
提交回复
热议问题