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

帅比萌擦擦* 提交于 2019-12-02 06:05:08

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!