Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. what to when error "Q_OBJECT macro but does not inherit from QObject" Appear ?
Forum Updated to NodeBB v4.3 + New Features

what to when error "Q_OBJECT macro but does not inherit from QObject" Appear ?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 508 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Qt embedded developer
    wrote on last edited by Qt embedded developer
    #1

    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})
    
    C 1 Reply Last reply
    0
    • Q Qt embedded developer

      @ChrisW67 Dear it is QObject based class. but for testing purpose i just simply added through qt creator and so it look like this.

      C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #4

      No, your class does not inherit from QObject. That is precisely what the error message is saying.

      Q 1 Reply Last reply
      4
      • Q Qt embedded developer

        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})
        
        C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #2

        @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?

        Q 1 Reply Last reply
        0
        • C ChrisW67

          @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?

          Q Offline
          Q Offline
          Qt embedded developer
          wrote on last edited by Qt embedded developer
          #3

          @ChrisW67 Dear it is QObject based class. but for testing purpose i just simply added through qt creator and so it look like this.

          C 1 Reply Last reply
          0
          • Q Qt embedded developer

            @ChrisW67 Dear it is QObject based class. but for testing purpose i just simply added through qt creator and so it look like this.

            C Offline
            C Offline
            ChrisW67
            wrote on last edited by
            #4

            No, your class does not inherit from QObject. That is precisely what the error message is saying.

            Q 1 Reply Last reply
            4
            • C ChrisW67

              No, your class does not inherit from QObject. That is precisely what the error message is saying.

              Q Offline
              Q Offline
              Qt embedded developer
              wrote on last edited by
              #5

              @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

              C 1 Reply Last reply
              0
              • Q Qt embedded developer has marked this topic as solved on
              • Q Qt embedded developer

                @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

                C Offline
                C Offline
                ChrisW67
                wrote on last edited by
                #6

                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.

                Q 1 Reply Last reply
                2
                • C ChrisW67

                  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.

                  Q Offline
                  Q Offline
                  Qt embedded developer
                  wrote on last edited by
                  #7

                  @ChrisW67 Sorry i have not updated the code over here.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved