[Interest] Understanding Qt Macros

Reinhardt Behm rbehm at hushmail.com
Sat Jan 3 13:48:17 CET 2015


On 03.01.2015 10:13, Alfredo Palhares wrote:
> Hello,
>
> First of all, let me say I am pretty new to this Qt and C++ thing.
>
> I recently adopted a Qt/C++ Linux desktop project. And I am currently
> looking on qmake builds the project itself.
>
> /usr/lib/qt4/bin/moc -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED
> -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore
> -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. configdata.h -o
> moc_configdata.cpp
>
> This is the moc that generated the C++ file.
>
> But qmake calls is it with all those macro definitions:
> - QT_GUI_LIB
> - QT_CORE_LIB
> - QT_SHARED
>
> What do these macros do ? I've tried to google the terms but no luck.
> Also how does qmake know when to call them ? Based on what terms ?
>
> Thanks in advance.
>
>
They are not documented, so you just should not use them.
But...
At least the QT_..._LIB macros seem to be controlled by what you have 
set in your .pro file for the QT variable.
I have used them to put together a commonly used header (see attached 
project.h), that I also use as a precompiled header.
This way all the required <Qt...> headers are automatically included.
But as mentioned above this is not documented and might fail, even if it 
has worked for me since Qt4.

The attached version is for Qt5 and Linux. You would need to selectively 
include the first Linux specific headers.
-- 
Reinhardt Behm


-------------- next part --------------
// ******************************************************
// * Copyright 2009-2014: (C) by Reinhardt Behm rbehm at hushmail.com
// * Released under GPL
// ******************************************************

#ifndef PROJECT_H
#define PROJECT_H

#include <unistd.h>
#include <math.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <iostream>

using namespace std;

#ifdef QT_CORE_LIB
#include <QtCore>
#endif

#ifdef QT_GUI_LIB
#include <QtGui>
#endif

#ifdef QT_WIDGETS_LIB
#include <QtWidgets>
#endif

#ifdef QT_NETWORK_LIB
#include <QtNetwork>
#endif

#ifdef QT_SERIALPORT_LIB
#include <QtSerialPort>
#endif

#ifdef QT_DBUS_LIB
#include <QtDBus>
#endif

#ifdef QT_OPENGL_LIB
#include <QtOpenGL>
#endif

#ifdef QT_XML_LIB
#include <QtXml>
#endif

#ifdef QT_SQL_LIB
#include <QtSql>
#endif

#ifdef QT_DBUS_LIB
#include <QtDBus>
#endif

#ifdef QT_WEBKIT_LIB
#include <QtWebKit>
#endif

#ifdef QT_WEBKITWIDGETS_LIB
#include <QtWebKitWidgets>
#endif

#ifdef QT_MULTIMEDIA_LIB
#include <QtMultimedia>
#endif

#ifdef QT_MULTIMEDIAWIDGETS_LIB
#include <QtMultimediaWidgets>
#endif

#ifdef QT_PRINTSUPPORT_LIB
#include <QtPrintSupport>
#endif

#ifdef QT_POSITIONING_LIB
#include <QtPositioning>
#endif

#ifdef QT_SENSORS_LIB
#include <QtXmlPatterns>
#endif

#ifdef QT_XMLPATTERNS_LIB
#include <QtSensors>
#endif

#ifdef QT_SVG_LIB
#include <QtSvg>
#endif

#ifdef QT_X11EXTRAS_LIB
#include <QtX11Extras>
#endif

#ifdef QT_UITOOLS_LIB
#include <QtUiTools>
#endif

#ifdef QT_BLUETOOTH_LIB
#include <QtBluetooth>
#endif

#endif



More information about the Interest mailing list