Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7858365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:23:55+00:00 2026-06-02T21:23:55+00:00

When compiling a non-Qt version of a Qt/C++ program (-DDISABLE_MYMODULE), I get this compiler

  • 0

When compiling a non-Qt version of a Qt/C++ program (-DDISABLE_MYMODULE), I get this compiler error:

src/mymodule.moc.cpp:12:2: error: #error "The header file
'mymodule.hpp' doesn't include <QObject>."
src/mymodule.moc.cpp:19:1: error: ‘QT_BEGIN_MOC_NAMESPACE’ does not name a type
src/mymodule.moc.cpp:40:6: error: ‘MyModule’ has not been declared
...

I’m using GNU make (not qmake). My Makefile compiles two object files per module, one directly from the .cpp source file and the MOC object file from the .moc.cpp source file (this is what doesn’t work), both using g++. This .moc.cpp source file is created by MOC, from the .hpp header (this process does not throw an error).

The header file in question looks somewhat like this:

#ifndef DISABLE_MYMODULE //My problem macro
#ifndef MYMODULE_HPP
#define MYMODULE_HPP
//...
class MyModule : //...
{
    Q_OBJECT //Qt problem macro
    //...
};
//...
#endif
#endif

The whole thing will compile (and later link, execute) just fine if don’t set my problem macro. If I do set it, but comment out QT’s problem macro, it’ll compile fine as well (building a non-Qt version).

I don’t exactly know, what MOC replaces Q_OBJECT by, but shouldn’t it still be inside my DISABLE_MYMODULE and therefore be removed by the preprocessor?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T21:24:01+00:00Added an answer on June 2, 2026 at 9:24 pm

    It looks like with your macro DISABLE_MYMODULE you exclude class definition, which includes Q_OBJECT. On the other hand, this code still processed by moc tool, which generates your mymodule.moc.cpp file, which in turn includes your mymodule.hpp header file. When mymodule.moc.cpp is then processed by compiler it includes .hpp file, but preprocessor excludes its content because of DISABLE_MYMODULE, so compiler do not find definition of the class, #include <QObject> and things to which Q_OBJECT macro should be expanded. So compiler do not find the things, which it expects to be and becom upset…

    I think, the solution will be to exclude mymodule.moc.cpp from build if DISABLE_MYMODULE is defined or (better) disable moc processing on mymodule.hpp, if DISABLE_MYMODULE is defined.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get this warning when compiling my code in VS2008 warning C4275: non dll-interface
While compiling a program in Java I got this big WARNING warning: [unchecked] unchecked
Compiling my project on new xcode4 using llvm 2.0 compiler I get a strange
Take this non-compiling code for instance: public string GetPath(string basefolder, string[] extraFolders) { string
My current non-compiling code is similar to this: public abstract class A { }
When I try to export my android application, I get this error message.. [2012-05-02
Compiling a kernel module on 32-Bit Linux kernel results in __udivdi3 [mymodule.ko] undefined! __umoddi3
Compiling this code with g++ 4.7.0 ( -Wall -Wextra -Werror -Wconversion -std=c++11 ): #include
When compiling my project with gcc and the -Wall option, I get a warning
when compiling some projects on linux terminal, I get usually a long output consisting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.