Uploaded image for project: 'Qt Visual Studio Tools'
  1. Qt Visual Studio Tools
  2. QTVSADDINBUG-792

MOC fails to handle declaration of Q_OBJECT classes in a CPP file.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Fixed
    • Affects Version/s: 2.5.1
    • Fix Version/s: 2.5.1 (rev.18), 2.5.2
    • Component/s: Qt/MSBuild
    • Labels:
      None
    • Platform/s:
      Windows
    • Commits:
      3b466a033f53f745cc37db0387fd3614186d2e76

      Description

      Project structure

      \---QtMoc
              QtClass.h
              QtClass2.cpp
              QtMoc.vcxproj           
      

      Environment

      • Visual Studio 19 - v16.6
      • Qt 5.15.0 - msvc2019

      Steps to reproduce

      In the attached project files, there are two different classes to reproduce this issue - QtClass.h & QtClass2.cpp:

      QtClass.h:

      #pragma once 
      #include <QObject> 
      class QtClass : public QObject 
      { Q_OBJECT };

      QtClass2.cpp:

      #include <QObject> 
      class QtClass2 : public QObject 
      { Q_OBJECT };
      #include "moc_QtClass2.cpp"
      

      When compiling this code, moc will produce under the QtMoc/Debug/moc/ directory these two files: moc_QtClass.cpp & moc_QtClass2.cpp.

      In the generated moc_QtClass.cpp file, it would add an include to the moced file ( #include "../../QtClass.h"), because it is a moced header file:
       
      In the generated moc_QtClass2.cpp file, it would not add the include, because it is a moced CPP file.
       
      By changing the extension of the QtClass2.cpp file to .H and removing the #include at the bottom of the file, it would compile without an issue.
       

      Desired behavior

      I'm not entirely sure how the VS extension would handle a scenario like this, but I believe it should compile this example as it used to be. Note that I encountered this issue while migrating some of my projects to use Qt's MsBuild new approach.

      This becomes problematic when some classes are using the PIMPL idiom or opaque pointer pattern.

      While compiling the QtService project:

      https://github.com/qtproject/qt-solutions/tree/master/qtservice

      I realized that the MOC in VS doesn't handle the QtServiceStarter & QtServiceControllerHandler as it used to be with fixed VS configurations - before migrating to Qt-MsBuild.

       

       

      Thank you once again!

      Kind regards,

      Gilad

        Attachments

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

          Activity

            People

            Assignee:
            mecfc Miguel Costa
            Reporter:
            gilad.reich Gilad Reich
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes