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

qt6_wrap_cpp doesn't work for C++ source files

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • 6.8.0 FF
    • 6.5.0
    • Build System: CMake
    • None
    • All
    • dc4159286 (dev)

    Description

      Consider the following example:

      // myobject2.h
      #ifndef MYOBJECT2_H
      #define MYOBJECT2_H
      
      void doSomethingWithMyObject2();
      
      #endif
      
      // myobject2.cpp
      #include "myobject2.h"
      #include <QObject>
      
      class MyObject2 : public QObject {
          Q_OBJECT
      public:
          MyObject2() = default;
      };
      
      void doSomethingWithMyObject2()
      {
          MyObject2 obj;
          obj.setObjectName("whatever");
      }
      
      #include "myobject2.moc"
      
      # CMakeLists.txt
      cmake_minimum_required(VERSION 3.16)
      project(qt-playground)
      set(CMAKE_AUTOMOC ON)
      find_package(Qt6 COMPONENTS Widgets REQUIRED)
      add_executable(qt-playground
          main.cpp
          myobject2.cpp
      )
      qt_wrap_cpp(genMocs myobject2.cpp TARGET qt-playground)
      message("XXX ${genMocs}")
      target_sources(qt-playground PRIVATE ${genMocs})
      

      One would expect that genMocs remains empty and that myobject2.moc is created. Instead, genMocs contains moc_myobject2.cpp and compilation fails, because myobject2.moc is missing.

      Attachments

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

        Activity

          People

            orkun.tokdemir Orkun Tokdemir
            jbornema Joerg Bornemann
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes