what to when error "Q_OBJECT macro but does not inherit from QObject" Appear ?
-
I have created the cmake project and in that when i link below class as static library i get the error
Q_OBJECT macro but does not inherit from QObject
#ifndef MAINAPPLICATION_H #define MAINAPPLICATION_H #include <QObject> class MAinApplication { Q_OBJECT public: MAinApplication(); }; #endif // MAINAPPLICATION_H
#include "MAinApplication.h" MAinApplication::MAinApplication() { }
cmakelist file
cmake_minimum_required(VERSION 3.6) project(Cmake1 LANGUAGES CXX) set(CMAKE_PREFIX_PATH "/home/HostName/Qt5.15.2/5.15.2/gcc_64" ${CMAKE_PREFIX_PATH}) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt5 COMPONENTS Core Quick REQUIRED) include_directories(${Qt5Widgets_INCLUDE_DIRS}) add_library(Component STATIC Components/MAinApplication.cpp Components/MAinApplication.h ) target_include_directories(Component PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Components) add_executable(Cmake1 App/Main.cpp ) set(QML_FILES App/Gui/qml.qrc) qt5_add_resources(QML_RESOURCES ${QML_FILES}) target_link_libraries(Cmake1 PUBLIC Qt5::Core Qt5::Quick Component) target_sources(Cmake1 PRIVATE ${QML_RESOURCES})
-
@ChrisW67 Dear it is QObject based class. but for testing purpose i just simply added through qt creator and so it look like this.
-
I have created the cmake project and in that when i link below class as static library i get the error
Q_OBJECT macro but does not inherit from QObject
#ifndef MAINAPPLICATION_H #define MAINAPPLICATION_H #include <QObject> class MAinApplication { Q_OBJECT public: MAinApplication(); }; #endif // MAINAPPLICATION_H
#include "MAinApplication.h" MAinApplication::MAinApplication() { }
cmakelist file
cmake_minimum_required(VERSION 3.6) project(Cmake1 LANGUAGES CXX) set(CMAKE_PREFIX_PATH "/home/HostName/Qt5.15.2/5.15.2/gcc_64" ${CMAKE_PREFIX_PATH}) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt5 COMPONENTS Core Quick REQUIRED) include_directories(${Qt5Widgets_INCLUDE_DIRS}) add_library(Component STATIC Components/MAinApplication.cpp Components/MAinApplication.h ) target_include_directories(Component PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Components) add_executable(Cmake1 App/Main.cpp ) set(QML_FILES App/Gui/qml.qrc) qt5_add_resources(QML_RESOURCES ${QML_FILES}) target_link_libraries(Cmake1 PUBLIC Qt5::Core Qt5::Quick Component) target_sources(Cmake1 PRIVATE ${QML_RESOURCES})
-
@Qt-embedded-developer What do you think you need the Q_OBJECT macro for if the class is not a QObject?
Are you perhaps looking for Q_GADGET?
@ChrisW67 Dear it is QObject based class. but for testing purpose i just simply added through qt creator and so it look like this.
-
@ChrisW67 Dear it is QObject based class. but for testing purpose i just simply added through qt creator and so it look like this.
-
No, your class does not inherit from QObject. That is precisely what the error message is saying.
@ChrisW67 Yes I have make it correct. but after that i got the error. But that i have solved by properly updating the CMAKE. and my ultimate goal is to check the cmake base build proper works or not and it works fine
-
-
@ChrisW67 Yes I have make it correct. but after that i got the error. But that i have solved by properly updating the CMAKE. and my ultimate goal is to check the cmake base build proper works or not and it works fine
-
Yes I have make it correct. but after that i got the error.
The code you posted is not correct and this has nothing to do with whether you use CMake, qmake, or hand rolled Makefiles to build it.
@ChrisW67 Sorry i have not updated the code over here.