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. class "has not been declared" in moc file though in class include is correct.
Forum Updated to NodeBB v4.3 + New Features

class "has not been declared" in moc file though in class include is correct.

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 3 Posters 211 Views 2 Watching
  • 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.
  • L lanigb

    Hi all,
    I am porting a project from QT4 to Qt6...
    At compile time, I got the following error:

    /home/alain/devel/ot2-src-1.1/build/Desktop_Qt_6_9_3-Debug/src/ot2_autogen/EWIEGA46WW/moc_otpicdisplay.cpp:38: erreur : ‘OTPicDisplay’ has not been declared
    In file included from /home/alain/devel/ot2-src-1.1/build/Desktop_Qt_6_9_3-Debug/src/ot2_autogen/mocs_compilation.cpp:42:
    /home/alain/devel/ot2-src-1.1/build/Desktop_Qt_6_9_3-Debug/src/ot2_autogen/EWIEGA46WW/moc_otpicdisplay.cpp:38:35: error: ‘OTPicDisplay’ has not been declared
       38 | template <> constexpr inline auto OTPicDisplay::qt_create_metaobjectdata<qt_meta_tag_ZN12OTPicDisplayE_t>()
    
      |                                   ^~~~~~~~~~~~
    

    The moc file does contains

    #include "../../../../../src/otpicdisplay.h"
    

    and OTPicDisplay contains the macro

    class OTPicDisplay : public  OTListViewItem
    {
      Q_OBJECT
    

    What puzzles me above all, it that it fails only for one class, all the other classes with Q_OBJECT have no problems. Any insight ?

    Christian EhrlicherC Online
    Christian EhrlicherC Online
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote last edited by
    #2

    @lanigb said in class "has not been declared" in moc file though in class include is correct.:

    Any insight ?

    You added the moc include in your header maybe.

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    L 1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      @lanigb said in class "has not been declared" in moc file though in class include is correct.:

      Any insight ?

      You added the moc include in your header maybe.

      L Offline
      L Offline
      lanigb
      wrote last edited by
      #3

      @Christian-Ehrlicher
      Thanks for your answer but his is not the case. I tried to include part of the header but was flagged a s "spam".

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote last edited by SGaist
        #4

        Hi,

        Can you share the full implementation of OTPicDisplay as well as OTListViewItem ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • L Offline
          L Offline
          lanigb
          wrote last edited by
          #5

          I will try in the next post, if you don't see it is because it is flagged as spam.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lanigb
            wrote last edited by
            #6

            Was marked as spam.
            http://alainbe.free.fr/qt/otpicdisplay.h
            http://alainbe.free.fr/qt/otpicdisplay.cpp
            http://alainbe.free.fr/qt/otlistviewitem.h
            http://alainbe.free.fr/qt/otlistviewitem.cpp

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote last edited by
              #7

              Are you using a .pro file ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • L Offline
                L Offline
                lanigb
                wrote last edited by lanigb
                #8

                No, CMakeList.txt

                cmake_minimum_required(VERSION 3.22)
                
                # Nom de l’exécutable final
                set(TARGET_NAME ot2)
                
                # Activer les outils automatiques de Qt
                set(CMAKE_AUTOMOC ON)
                set(CMAKE_AUTOUIC ON)
                set(CMAKE_AUTORCC ON)
                
                # Encodage par défaut
                set(CMAKE_CXX_STANDARD 17)
                set(CMAKE_CXX_STANDARD_REQUIRED ON)
                
                # Trouver Qt6 et ses modules nécessaires
                find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Sql Xml PrintSupport)
                
                # Récupération des fichiers
                file(GLOB_RECURSE PROJECT_SOURCES
                    "*.cpp"
                    "*.h"
                    "*.ui"
                    "*.qrc"
                )
                
                # Création de l’exécutable
                qt_add_executable(${TARGET_NAME}
                    ${PROJECT_SOURCES}
                )
                
                # Lien avec les bibliothèques Qt nécessaires
                target_link_libraries(${TARGET_NAME}
                    PRIVATE
                        Qt6::Core
                        Qt6::Gui
                        Qt6::Widgets
                        Qt6::Sql
                        Qt6::Xml
                        Qt6::PrintSupport
                )
                
                # Dossier de sortie
                set_target_properties(${TARGET_NAME} PROPERTIES
                    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin
                )
                
                # Inclure le répertoire courant (pour que les includes relatifs fonctionnent)
                target_include_directories(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
                
                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote last edited by
                  #9

                  I would suggest following the cmake getting started guide. There are some hints to simplify the content of your CMakeLists.txt file.

                  One of which is to not include the headers in the file list you pass to qt_add_executable.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1
                  • L Offline
                    L Offline
                    lanigb
                    wrote last edited by
                    #10

                    OK. Thanks for the link.

                    1 Reply Last reply
                    0
                    • L Offline
                      L Offline
                      lanigb
                      wrote last edited by lanigb
                      #11

                      I have rewritten the CMakeList.txt. For now, I don't know whether this point is better or not because I have new problems.

                      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