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

unresolved external symbol Q_OBJECT and #define

    XMLWordPrintable

Details

    • Windows

    Description

      If i have any class in a header file that uses Q_OBJECT and is inside a #if ... #endif block, it fails to compile, i get errors like this:

      unresolved external symbol "public: virtual struct QMetaObject const * __cdecl Widget::metaObject(void)const " (?metaObject@Widget@@UEBAPEBUQMetaObject@@XZ)
      
      unresolved external symbol "public: virtual void * __cdecl Widget::qt_metacast(char const *)" (?qt_metacast@Widget@@UEAAPEAXPEBD@Z)
      
      unresolved external symbol "public: virtual int __cdecl Widget::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Widget@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)
      
      3 unresolved externals

      This issue can be reproduced with this simple example:

      //test.h
      #pragma once  
      
      #if CUSTOM_WIDGET
      
      class Widget : public QWidget
      {
         Q_OBJECT
      public:	
         Widget(QWidget* parent = nullptr);
      };
      
      #endif 
      // stdafx.h
      #include <QtWidgets>
      #define CUSTOM_WIDGET 1
      

      Commenting Q_OBJECT or #if CUSTOM_WIDGET in test.h it does compile correctly.

       

      I'm testing using:

      VS22 Version 17.14.0 Preview 4.0,

      Qt Extension 3.3.1.1,

      Qt Source 6.6.0,

      Windows 10.

      Attachments

        Issue Links

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

          Activity

            People

              qtvstools Qt VS Tools
              lilo Lilo Black
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes