[Interest] Understanding Qt Macros

Thiago Macieira thiago.macieira at intel.com
Sat Jan 3 11:55:20 CET 2015

On Saturday 03 January 2015 11:30:01 René J.V. Bertin wrote:
> On Saturday January 03 2015 03:13:41 Alfredo Palhares wrote:
> >But qmake calls is it with all those macro definitions:
> >
> >What do these macros do ? I've tried to google the terms but no luck.
> Those are likely Qt internal macros, as Guido said. My guess is that they
> serve to activate select parts in the headers, depending on the
> application's requirements. In this case, that would be an application that
> uses QtGui in addition to QtCore (not sure if you can have a Qt application
> without that...) and that either uses Qt shared libraries (as opposed to
> static builds) or uses Qt classes for sharing data among applications
> (QSharedMemory and friends).

In theory, all QT_xxx macros are internal API, while all Q_xxx ones are public 
and should be documented. In practice, we've used the wrong type over the 

The QT_xxx_LIB macros are added by qmake to indicate that you're linking to 
module xxx. Most of the time, they're simple indications to you and have 
little effect on anything in the API anyway. The only difference is that 
<QtTest> enables some QtGui and QtWidgets parts if the macros for those libs 
are defined.

The QT_SHARED macro is wrong to come from qmake. That was a major mistake in 
Qt 4 but is fixed in Qt 5. That is now defined in qconfig.h and indicates whether 
you're linking to a shared/DLL version of Qt. The QT_STATIC macro is its 
counterpart. That in turn means there's no support for a shared-and-static 
build of Qt.

> As Guido also said: no need to worry about these. Or, AFAIK, about "black
> magic" formulas involving moc and friends ... until you're really running
> into failures that have no other explanation. (Which they usually will
> have, just as a seemingly inexplicable bug is rarely ever due to a compiler
> bug.)

Failures without explanation usually mean preprocessor errors.

> >Also how does qmake know when to call them ? Based on what terms ?
> Your .pro file will have a CONFIG line that tells qmake what Qt
> features/libraries/frameworks your application requires.

Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center

More information about the Interest mailing list