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

moc does not process QT_HAS_INCLUDE

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.11, 5.14.0, 6.0
    • Build tools: moc
    • None
    • Windows 10
    • Windows

    Description

      I've encountered an interesting bug/feature in moc: if a slot is defined inside a preprocessor conditional with QT_HAS_INCLUDE, it is not processed by moc: 

       

      class MyClass : public QObject
      {
          Q_OBJECT
          
      public slots:
          void unconditionalSlot();
          
      #if QT_HAS_INCLUDE(<chrono>)
          void conditionalSlot1();
      #endif
      
      };

      The output of moc does not include the conditionalSlot1, although I am sure that the conditional evaluates to true: my compiler does have <chrono> and the function can be actually called in runtime. 

      I've attached an example project to reproduce this problem. The example project has three slots enclosed with three types of preprocessor conditionals: QT_HAS_INCLUDE, ifdef, and 'if defined', the latter two are working:

      public slots:
      // this one doesn't work
      #if QT_HAS_INCLUDE(<chrono>)   
          void conditionalSlot1();
      #endif
      
      // this works
      #ifdef MY_DEFINE 
          void conditionalSlot2();
      #endif 
      
      // this works
      #if defined(MY_DEFINE)
          void conditionalSlot3();
      #endif

      There is also another slot enclosed with a normal ifdef but its define is inside a QT_HAS_INCLUDE, and this doesn't work as well: 

      #if QT_HAS_INCLUDE(<chrono>)
      #define MY_OTHER_DEFINE
      #endif
      
      class MyClass : public QObject
      {
          Q_OBJECT
          
      public slots:
      // doesn't work
      #ifdef MY_OTHER_DEFINE
          void conditionalSlot4();
      #endif 
          
      };

      The example project calls all the slots one by one (all four slots can be called as normal functions) and then checks whether they are registered in the meta-object. The slots 1 and 4 that depend on QT_HAS_INCLUDE are not registered in the meta-object.

      I've tested this on Windows with MinGW versions of Qt 5.11, Qt 5.14, and the Qt version from the dev branch, and this problem can be reproduced everywhere.

       

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            dpurgin Dmitriy Purgin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes