no header providing "Q_OBJECT" is directly included
-
Hi,
I use Qt Creator 18.0.1 and Qt 6.10.1 to compile my project. In Qt Creator I get the following warningcommand-controller.h:41:4: no header providing "Q_OBJECT" is directly included [misc-include-cleaner]But in my code I includ <QObject>.
#ifndef COMMAND_CONTROLLER_H #define COMMAND_CONTROLLER_H // Includes //--------------------------------------------------------------------------------------------------------------------- // own header // other includes #include "framework/command.h" #include "navigation-controller.h" #include "sp-new.h" #include "sp.h" #include "wm-lib_global.h" // system includes #include <QObject> #include <QList> #include <QtQml/QQmlListProperty> // Macros/Defines //---------------------------------------------------------------------------------------------------------------------- // Forward declarations //---------------------------------------------------------------------------------------------------------------------- using namespace Framework; namespace Controllers { class WMLIBSHARED_EXPORT CommandController : public QObject { Q_OBJECT Q_PROPERTY(QQmlListProperty<Framework::Command> uiEditViewContextCommands READ uiEditViewContextCommands CONSTANT) Q_PROPERTY(QQmlListProperty<Framework::Command> uiImageViewContextCommands READ uiImageViewContextCommands CONSTANT) Q_PROPERTY(QQmlListProperty<Framework::Command> uiFindViewContextCommands READ uiFindViewContextCommands CONSTANT) Q_PROPERTY(QQmlListProperty<Framework::Command> uiSpMapViewContextCommands READ uiSpMapViewContextCommands CONSTANT) Q_PROPERTY(QQmlListProperty<Framework::Command> uiNewViewContextCommands READ uiNewViewContextCommands CONSTANT) Q_PROPERTY(QQmlListProperty<Framework::Command> uiImageAddContextCommands READ uiImageAddContextCommands CONSTANT)How can I avoid this warnings?
Thank you for your help
BR
Martin -
C Christian Ehrlicher moved this topic from General and Desktop
-
Hi @msauer751,
I can't reproduce this with Creator 18.0.1 and Qt 6.10.2.
The patch release difference shouldn't be the reason.At first, please try including the Qt stuff first. Maybe some of the project specific includes already hit the pragma, making
#include <QObject>toothless.Maybe the include path is broken. You could check this by double clicking on the
QObjectinclude statement and see where you land.As a last resort, you can try to
#include <qobjectdefs.h>directly. Hammer-fix, a kitten will die. -
Hi @msauer751,
I can't reproduce this with Creator 18.0.1 and Qt 6.10.2.
The patch release difference shouldn't be the reason.At first, please try including the Qt stuff first. Maybe some of the project specific includes already hit the pragma, making
#include <QObject>toothless.Maybe the include path is broken. You could check this by double clicking on the
QObjectinclude statement and see where you land.As a last resort, you can try to
#include <qobjectdefs.h>directly. Hammer-fix, a kitten will die. -
Hi,
Then something is off. Including QObject should be enough.
Which project management system are you using ? qmake or cmake ? -
Hi,
Then something is off. Including QObject should be enough.
Which project management system are you using ? qmake or cmake ?Hi @SGaist
cmake.
And with CMakeLists.txt of the project
cmake_minimum_required(VERSION 3.16) set(APP "qt_wm") set(VER "1.0") message("CMAKE fuer project: " ${APP}) project(${APP} VERSION ${VER} LANGUAGES CXX) #set(CMAKE_BINARY_DIR "${CMAKE_SOURCE_DIR}/_Build/Bin/${CMAKE_SYSTEM_NAME}/${CMAKE_BUILD_TYPE}") #set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) #set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) #set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) set(LIBTYP "SHARED") set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) #set(CMAKE_CXX_CLANG_TIDY clang-tidy) if (WIN32) set(SSLDIR "E:/Qt/Tools/OpenSSLv3/Win_x64/bin/") set(SSLLIB1 "libcrypto-3-x64.dll") set(SSLLIB2 "libssl-3-x64.dll") message(" WIN32: SSLDIR=" ${SSLDIR}) message(" WIN32: SSLLIB=" ${SSLLIB1} " " ${SSLLIB2}) elseif (UNIX) #set(CMAKE_PREFIX_PATH "/opt/Entwicklung/Qt/6.10.1/gcc_64/") endif() add_subdirectory(library/lib-datad) add_subdirectory(library/lib-db) add_subdirectory(library/lib-geo) add_subdirectory(library/lib-jsonrpc) add_subdirectory(wm-lib) add_subdirectory(wm-ui)and of the subproject:
cmake_minimum_required(VERSION 3.16) set(LIB "datad") set(LIBDEF "LIBDATAD_LIBRARY") message("CMAKE fuer project: lib" ${LIB}) project(lib-${LIB} VERSION 1.0.0 LANGUAGES CXX) find_package(Qt6 COMPONENTS Core REQUIRED) find_package(Qt6 COMPONENTS Qml REQUIRED) include_directories("source/") include_directories("source/helper") set(SOURCES source/data-decorator.cpp source/bool-decorator.cpp source/float-decorator.cpp source/int-decorator.cpp source/string-decorator.cpp source/enumerator-decorator.cpp source/dropdown.cpp source/helper/dropdown-value.cpp source/helper/koordinaten.cpp source/string_bool-decorator.cpp source/koordinaten-decorator.cpp source/attribute-decorator.cpp source/lib-datad_global.h source/data-decorator.h source/bool-decorator.h source/float-decorator.h source/int-decorator.h source/string-decorator.h source/enumerator-decorator.h source/dropdown.h source/helper/dropdown-value.h source/string_bool-decorator.h source/koordinaten-decorator.h source/attribute-decorator.h source/helper/koordinaten.h ) add_library(${LIB} ${LIBTYP} ${SOURCES}) target_link_libraries( ${LIB} Qt6::Core ) target_compile_definitions(${LIB} PRIVATE ${LIBDEF}) target_compile_definitions(${LIB} PUBLIC "QT_DEPRECATED_WARNINGS")