class "has not been declared" in moc file though in class include is correct.
-
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 ?
@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.
-
@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.
@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". -
Hi,
Can you share the full implementation of
OTPicDisplay
as well asOTListViewItem
? -
Are you using a
.pro
file ? -
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})
-
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
.