Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-102965

File order of CMake project can break compilation due to QMetaTypeId<T> specialization

    XMLWordPrintable

Details

    • caf35f0fed (qt/qtdeclarative/dev) caf35f0fed (qt/tqtc-qtdeclarative/dev) 83ee126fb0 (qt/tqtc-qtdeclarative/6.2) 57c9982e0f (qt/qtdeclarative/6.4) 304196a4fe (qt/qtdeclarative/6.3) 304196a4fe (qt/tqtc-qtdeclarative/6.3)

    Description

      See the attached project. Given the following headers...

      // obj1.h
      #ifndef OBJ1_H
      #define OBJ1_H
      
      #include <QObject>
      
      class Obj1 : public QObject
      {
          Q_OBJECT
          Q_PROPERTY(QObjectList objs MEMBER m_objs)
      
      private:
          QObjectList m_objs;
      };
      
      #endif // OBJ1_H
      
      
      // obj2.h
      #ifndef OBJ2_H
      #define OBJ2_H
      
      #include <QQmlContext>
      
      class Obj2 : public QObject
      {
          Q_OBJECT
      };
      
      #endif // OBJ2_H
      

       

      ... we get this error:

      [1/3 6.0/sec] Automatic MOC for target appSimpleApp
      [2/3 1.4/sec] Building CXX object CMakeFiles\appSimpleApp.dir\appSimpleApp_autogen\mocs_compilation.cpp.obj
      FAILED: CMakeFiles/appSimpleApp.dir/appSimpleApp_autogen/mocs_compilation.cpp.obj 
      C:\PROGRA~2\MIB055~1\2019\COMMUN~1\VC\Tools\MSVC\1429~1.301\bin\HostX64\x64\cl.exe  /nologo /TP -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_OPENGL_LIB -DQT_QMLINTEGRATION_LIB -DQT_QMLMODELS_LIB -DQT_QML_DEBUG -DQT_QML_LIB -DQT_QUICK_LIB -DUNICODE -DWIN32 -DWIN64 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -D_UNICODE -D_WIN64 -ID:\SimpleApp\build-SimpleApp-Desktop_Qt_6_3_0_MSVC2019_64bit-Debug\appSimpleApp_autogen\include -IC:\Qt\6.3.0\msvc2019_64\include\QtCore -IC:\Qt\6.3.0\msvc2019_64\include -IC:\Qt\6.3.0\msvc2019_64\mkspecs\win32-msvc -IC:\Qt\6.3.0\msvc2019_64\include\QtQuick -IC:\Qt\6.3.0\msvc2019_64\include\QtGui -IC:\Qt\6.3.0\msvc2019_64\include\QtQml -IC:\Qt\6.3.0\msvc2019_64\include\QtQmlIntegration -IC:\Qt\6.3.0\msvc2019_64\include\QtNetwork -IC:\Qt\6.3.0\msvc2019_64\include\QtQmlModels -IC:\Qt\6.3.0\msvc2019_64\include\QtOpenGL /DWIN32 /D_WINDOWS /GR /EHsc /Zi /Ob0 /Od /RTC1 -MDd -Zc:__cplusplus -permissive- -utf-8 -std:c++17 /showIncludes /FoCMakeFiles\appSimpleApp.dir\appSimpleApp_autogen\mocs_compilation.cpp.obj /FdCMakeFiles\appSimpleApp.dir\ /FS -c D:\SimpleApp\build-SimpleApp-Desktop_Qt_6_3_0_MSVC2019_64bit-Debug\appSimpleApp_autogen\mocs_compilation.cpp
      C:\Qt\6.3.0\msvc2019_64\include\QtQml\qqmlcontext.h(111): error C2908: explicit specialization; 'QMetaTypeId<T>' has already been instantiated
              with
              [
                  T=Ty
              ]
      C:\Qt\6.3.0\msvc2019_64\include\QtQml\qqmlcontext.h(111): error C2766: explicit specialization; 'QMetaTypeId<T>' has already been defined
              with
              [
                  T=Ty
              ]
      C:\Qt\6.3.0\msvc2019_64\include\QtCore/qmetatype.h(1145): note: see previous definition of 'QMetaTypeId<QList<QObject *> >'
      

       

      Workarounds

      Either of the following will make the compilation succeed:

      • Add `#include <QQmlContext>` to obj1.h, OR
      • Rename "obj2.h" -> "aaa.h" so that it gets processed before obj1.h

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            ievgenii.meshcheriakov Ievgenii Meshcheriakov
            skoh-qt Sze Howe Koh
            Votes:
            5 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes