PDA

View Full Version : Qt4 Preprocessor defines



Chicken Blood Machine
14th March 2006, 18:33
Does anyone know how to get a definitive list of the Qt preprocessord defnes and what they are for/ when they should be used?

For example QT_DLL, QT_SHARED, QT_CORE_LIB, etc.

For example, QT_NETWORK_LIB should only be defined when using -lQtNetwork, QT_DLL should only be defined when using Qt DLLs on Windows, etc.

These are all automatically inserted by qmake, but if I am using a build system other than qmake, I need to know them.

I have tried looking through the makespecs directory and grepping the sources, but it is not clear to me exactly what the rules are for setting these flags.

I couldn't find anything clear and definitive on the Trolltech website either.

wysota
14th March 2006, 20:16
I don't think such a list exists. Some of the defines are for internal use only, some are explained either in the sources or in the docs. You could ask Trolltech for this, but I would expect an answer simmilar to "they are not to be used".

Michiel
14th March 2006, 20:46
Q_OBJECT is used, right? Aren't there others?

Chicken Blood Machine
14th March 2006, 20:56
I don't think such a list exists. Some of the defines are for internal use only, some are explained either in the sources or in the docs. You could ask Trolltech for this, but I would expect an answer simmilar to "they are not to be used".

Obviously I'm only interested in the correct defines required to build a program that uses Qt, not the internal ones.

I will ask Trolltech and post the results here.

ldindon
15th March 2006, 07:18
Yop,

You don't have to care about these defines. They are automatically set by qmake. Just configure your .pro and let qmake does its job.

For instance, you talked about QtNetwork module. Just add this line in your .pro file and qmake will add the QT_NETWORK_LIB building flag.



QT += network


If you want to know which option to append to QT .pro file variable, just open the QtAssistant and type the module name in the "Look for" entry of the index tab (eg: QtNetwork for the above example).

Chicken Blood Machine
15th March 2006, 16:43
Yop,

Who?

You don't have to care about these defines. They are automatically set by qmake. Just configure your .pro and let qmake does its job.

Read my post again. I was talking about specifically when not using qmake. We use a totally different build system where I work.

Chicken Blood Machine
15th March 2006, 17:30
Here's the reply I got from Trolltech:



Some of them I guess can be found here.

http://doc.trolltech.com/4.1/qtglobal.html

Others are scattered around the qmake docs. E.g. here:

http://doc.trolltech.com/4.1/qmake-advanced-usage.html

There are still quite a few that are undocumented I am afraid.


...which is kind of unsubstantial. I can probably get close enough by observing the output from qmake-generated Makefiles, which is basically:

QT_DLL/QT_NODLL - define one or the other depending on whether using shared or static Qt libraries.

QT_NO_DEBUG/QT_DEBUG - define one or the other depending on whether using release or debug Qt

QT_PLUGIN - define when building a plugin library.

Define these accoring to which Qt libs you are linking with:
QT_CORE_LIB
QT_GUI_LIB
QT_XML_LIB
QT_NETWORK_LIB
QT_QT3SUPPORT_LIB
QT_OPENGL_LIB
QT_SQL_LIB
QT_SVG_LIB

These two only seem to be defined on Windows. (I was under the impression that multi-threading and 64-bit file offsets were the default in Qt4 anyway...).
QT_LARGEFILE_SUPPORT
QT_THREAD_SUPPORT

QT_SHARED - not sure what this is for?

wysota
15th March 2006, 21:04
QT_SHARED - not sure what this is for?

It probably means you're linking with shared Qt library. But IMHO this should only influence building Qt itself, not projects using it.

Chicken Blood Machine
15th March 2006, 21:13
It probably means you're linking with shared Qt library. But IMHO this should only influence building Qt itself, not projects using it.

Yeah, I would tend to agree, since QT_DLL, implies that you are linking with the shared Qt library, I would have guessed that QT_SHARED was an internal flag used when building Qt. Nevertheless, my small test program (on Suse Linux) shows a compile line containing -DQT_SHARED, when building a Makefile that was generated by qmake. Curious...

dimitri
19th March 2006, 11:23
QT_NO_DEBUG/QT_DEBUG - define one or the other depending on whether using release or debug Qt
QT_NO_DEBUG is defined in the Debugging Techniques (http://doc.trolltech.com/4.1/debug.html#debugging-macros) paragraph of the manual. QT_DEBUG looks like an internal Qt macro that shouldn't be used by programmers.


QT_PLUGIN - define when building a plugin library.
This looks like an internal Qt macro that shouldn't be used by programmers.


Define these accoring to which Qt libs you are linking with:
QT_CORE_LIB
QT_GUI_LIB
QT_XML_LIB
QT_NETWORK_LIB
QT_QT3SUPPORT_LIB
QT_OPENGL_LIB
QT_SQL_LIB
QT_SVG_LIB
I don't think any of these need to be defined, do they? They look like internal macros to me.


These two only seem to be defined on Windows. (I was under the impression that multi-threading and 64-bit file offsets were the default in Qt4 anyway...).
QT_LARGEFILE_SUPPORT
QT_THREAD_SUPPORT
These are indeed for Qt 3 only, they have no effect whatsoever in Qt 4.

QT_LARGEFILE_SUPPORT is an internal macro that shouldn't be used by programmers. QT_THREAD_SUPPORT is defined in paragraph Thread Support in Qt (http://doc.trolltech.com/3.3/threads.html#2) of the Qt 3 manual.

Chicken Blood Machine
20th March 2006, 01:43
OK, there's a lot of misunderstanding here. Here goes...


QT_NO_DEBUG is defined in the Debugging Techniques (http://doc.trolltech.com/4.1/debug.html#debugging-macros) paragraph of the manual. QT_DEBUG looks like an internal Qt macro that shouldn't be used by programmers.


My questions are about what I need to have defined when building a project that uses the Qt libraries, but I using a build system other than qmake (i.e. what is automatically defined when using qmake). This is easy to see when looking at the compile commands invoked when calling 'make' on a makefile generated by qmake.

QT_DEBUG is one of of such macros that need to be defined. Look at the output of any build when using CONFIG += debug.



QT_PLUGIN - define when building a plugin library

This looks like an internal Qt macro that shouldn't be used by programmers.


See above. It does need to be defined when compiling a plugin.



Define these accoring to which Qt libs you are linking with:
QT_CORE_LIB
QT_GUI_LIB
QT_XML_LIB
QT_NETWORK_LIB
QT_QT3SUPPORT_LIB
QT_OPENGL_LIB
QT_SQL_LIB
QT_SVG_LIB

I don't think any of these need to be defined, do they? They look like internal macros to me.


Again - see above. qmake defines them all. Looking through the code, some of them don't seem to do anything (yet) but they may do in the future.



These two only seem to be defined on Windows. (I was under the impression that multi-threading and 64-bit file offsets were the default in Qt4 anyway...).
QT_LARGEFILE_SUPPORT
QT_THREAD_SUPPORT

These are indeed for Qt 3 only, they have no effect whatsoever in Qt 4.


You're probably right about these, but qmake still seems to define them on Windows. I am using Qt 4.1.0, YMMV.

So to sum up - Nearly all need to be defined under some circumstance or another. I just wanted to know the full list of macros and what those cicumstances were. Nevertheless I've worked most of it out myself by looking at the source. Hopefully there will be no nasty suprises down the road . My build system seems to be functioning correctly anyway.

dimitri
23rd March 2006, 06:28
I don't think all of these macros need to be defined when building your own programs. For example QT_DEBUG clearly shouldn't need to be defined - from qglobal.h:
/*
Debugging and error handling
*/

#if !defined(QT_NO_DEBUG) && !defined(QT_DEBUG)
# define QT_DEBUG
#endif
The fact that qmake defines them doesn't necessarily mean you need them, qmake may define them because they're needed for building Qt itself.

That said, it's not a good idea for qmake to define macros that are not needed. Also it would indeed be a good idea to list all needed macros in a paragraph of the documentation. These really should be reported as a bug to Trolltech...

Chicken Blood Machine
23rd March 2006, 16:28
The fact that qmake defines them doesn't necessarily mean you need them, qmake may define them because they're needed for building Qt itself.


Indeed.



That said, it's not a good idea for qmake to define macros that are not needed. Also it would indeed be a good idea to list all needed macros in a paragraph of the documentation. These really should be reported as a bug to Trolltech...

My sentiments entirely.