moc-generated code error at Qt6 when not at Qt5
-
@Axel-Spoerl
I have now changed over to cmake (projectmocerror2
). FWIW myCMakeLists.txt
:cmake_minimum_required(VERSION 3.14) project(mocerror2 LANGUAGES CXX) 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(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) add_executable(mocerror2 main.cpp bar.cpp bar.h foo.cpp foo.h ) target_link_libraries(mocerror2 Qt${QT_VERSION_MAJOR}::Core) include(GNUInstallDirs) install(TARGETS mocerror2 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
As I expected it makes no difference and I get same error:
[ 14%] Automatic MOC and UIC for target mocerror2 [ 14%] Built target mocerror2_autogen [ 28%] Building CXX object CMakeFiles/mocerror2.dir/mocerror2_autogen/mocs_compilation.cpp.o In file included from /usr/include/x86_64-linux-gnu/qt6/QtCore/qobject.h:18, from /usr/include/x86_64-linux-gnu/qt6/QtCore/QObject:1, from /home/jon/QtTests/mocerror2/build/Desktop-Debug/mocerror2_autogen/EWIEGA46WW/../../../../foo.h:5, from /home/jon/QtTests/mocerror2/build/Desktop-Debug/mocerror2_autogen/EWIEGA46WW/moc_foo.cpp:10, from /home/jon/QtTests/mocerror2/build/Desktop-Debug/mocerror2_autogen/mocs_compilation.cpp:2: /usr/include/x86_64-linux-gnu/qt6/QtCore/qmetatype.h: In instantiation of ‘struct QtPrivate::IsPointerToTypeDerivedFromQObject<Bar*>’: /usr/include/x86_64-linux-gnu/qt6/QtCore/qmetatype.h:1102:60: required from ‘struct QMetaTypeId<Bar*>’ /usr/include/x86_64-linux-gnu/qt6/QtCore/qmetatype.h:1122:38: required from ‘struct QMetaTypeId2<Bar*>’ /usr/include/x86_64-linux-gnu/qt6/QtCore/qmetatype.h:1585:1: required from ‘struct QMetaTypeId<QList<Bar*> >’ /usr/include/x86_64-linux-gnu/qt6/QtCore/qmetatype.h:2364:42: recursively required by substitution of ‘template<class T> struct QtPrivate::BuiltinMetaType<T, typename std::enable_if<QMetaTypeId2<T>::IsBuiltIn, void>::type> [with T = QList<Bar*>]’ /usr/include/x86_64-linux-gnu/qt6/QtCore/qmetatype.h:2364:42: required from ‘constexpr const QtPrivate::QMetaTypeInterface QtPrivate::QMetaTypeInterfaceWrapper<QList<Bar*> >::metaType’ /usr/include/x86_64-linux-gnu/qt6/QtCore/qmetatype.h:2486:16: required from ‘constexpr const QtPrivate::QMetaTypeInterface* QtPrivate::qTryMetaTypeInterfaceForType() [with Unique = {anonymous}::qt_meta_stringdata_Foo_t; TypeCompletePair = TypeAndForceComplete<QList<Bar*>, std::integral_constant<bool, false> >]’ /usr/include/x86_64-linux-gnu/qt6/QtCore/qmetatype.h:2537:55: required from ‘constexpr const QtPrivate::QMetaTypeInterface* const qt_incomplete_metaTypeArray [5]<{anonymous}::qt_meta_stringdata_Foo_t, QtPrivate::TypeAndForceComplete<Foo, std::integral_constant<bool, true> >, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<Bar*, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<QList<Bar*>, std::integral_constant<bool, false> > >’ /home/jon/QtTests/mocerror2/build/Desktop-Debug/mocerror2_autogen/EWIEGA46WW/moc_foo.cpp:95:5: required from here /usr/include/x86_64-linux-gnu/qt6/QtCore/qmetatype.h:842:23: error: invalid application of ‘sizeof’ to incomplete type ‘Bar’ 842 | static_assert(sizeof(T), "Type argument of Q_PROPERTY or Q_DECLARE_METATYPE(T*) must be fully defined"); | ^~~~~~~~~ gmake[2]: *** [CMakeFiles/mocerror2.dir/build.make:82: CMakeFiles/mocerror2.dir/mocerror2_autogen/mocs_compilation.cpp.o] Error 1 gmake[1]: *** [CMakeFiles/Makefile2:86: CMakeFiles/mocerror2.dir/all] Error 2 gmake: *** [Makefile:136: all] Error 2 10:38:41: The process "/usr/bin/cmake" exited with code 2.
I do not understand why you do not get same error as I do.
My gcc is 13.2.0. My moc is 6.4.2 as is my Qt6.
-
I am using gcc 13.3.0, moc 6.9.0.
The only difference in our CMake files is that I require 3.16, you require 3.14. -
@Axel-Spoerl
Thank you. So what would you like me to do about our difference in behaviour? :)
[I fetch all my Qt stuff fromapt
as supplied with Ubuntu 24.04 distro.] -
I actually remember something similar, early when QVector was nuked for QList to prosper.
I think if you change it from
QList<Bar *>bars
toQList<Bar *> *bars
it actually works. Axel is using a way later Qt6 version ( 6.8 vs 6.4.2) QList was probably touched again in between those versions, to fix this :D -
@J-Hilk said in moc-generated code error at Qt6 when not at Qt5:
I think if you change it from
QList<Bar *>bars
toQList<Bar *> *bars
it actually works.But those are quite different types! :) Are you just showing me that to say what it could cope with?
Axel is using a way later Qt6 version ( 6.8 vs 6.4.2) QList was probably touched again in between those versions, to fix this :D
Ah! Well in that case it's obviously not to be reported. Thanks for the heads-up.
With Qt5 I always had Qt 5.15 (or maybe 5.12) via
apt
under various Ubuntu releases over the years. And I have to say that was just great, I didn't encounter problems and I didn't need later versions. I suspected Qt6 would be problematic, looks like I get a quite older version and am going to have issues which really need a later version from TQtC :( Ho-hum.... -
- I have never even attempted to download from TQtC, having seen the endless problems with downloads/mirrors. Fills me with dread....
- ...As does when I see people who for whatever reason (e.g. maybe to do with configuration, whatever it happens) get an error during compilation of the whole of Qt....
- I don't have the disk space in VM for Qt sources + compilation outputs.
- I don't have the memory in VM to compile it. Not to mention the requirements for
QWebEngine
. - I share (development) with other people using Qt from Ubuntu distro. They are not going to want to fetch/compile/install or take from me.
Am I being difficult? ;-) It was all so simple with Qt5, everything worked. Now beginning to think of backing out of the whole of Qt6 and reverting to Qt5. But that would be a shame for my answering questions on this forum.
-