Results 1 to 13 of 13

Thread: Qt4 Preprocessor defines

  1. #1
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Qt4 Preprocessor defines

    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.
    Save yourself some pain. Learn C++ before learning Qt.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt4 Preprocessor defines

    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".

  3. #3
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Qt4 Preprocessor defines

    Q_OBJECT is used, right? Aren't there others?
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  4. #4
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4 Preprocessor defines

    Quote Originally Posted by wysota
    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.
    Save yourself some pain. Learn C++ before learning Qt.

  5. #5
    Join Date
    Feb 2006
    Location
    France (Metz)
    Posts
    5
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt4 Preprocessor defines

    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.


    [HTML]QT += network[/HTML]


    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).

  6. #6
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4 Preprocessor defines

    Quote Originally Posted by ldindon
    Yop,
    Who?
    Quote Originally Posted by ldindon
    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.
    Save yourself some pain. Learn C++ before learning Qt.

  7. #7
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4 Preprocessor defines

    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?
    Save yourself some pain. Learn C++ before learning Qt.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt4 Preprocessor defines

    Quote Originally Posted by Chicken Blood Machine
    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.

  9. #9
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4 Preprocessor defines

    Quote Originally Posted by wysota
    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...
    Save yourself some pain. Learn C++ before learning Qt.

  10. #10
    Join Date
    Jan 2006
    Posts
    109
    Thanks
    2
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Qt4 Preprocessor defines

    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 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 of the Qt 3 manual.

  11. #11
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4 Preprocessor defines

    OK, there's a lot of misunderstanding here. Here goes...

    Quote Originally Posted by dimitri
    QT_NO_DEBUG is defined in the Debugging Techniques 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.
    Save yourself some pain. Learn C++ before learning Qt.

  12. #12
    Join Date
    Jan 2006
    Posts
    109
    Thanks
    2
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Qt4 Preprocessor defines

    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:
    Qt Code:
    1. /*
    2.   Debugging and error handling
    3. */
    4.  
    5. #if !defined(QT_NO_DEBUG) && !defined(QT_DEBUG)
    6. # define QT_DEBUG
    7. #endif
    To copy to clipboard, switch view to plain text mode 
    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...

  13. #13
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt4 Preprocessor defines

    Quote Originally Posted by dimitri
    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.
    Save yourself some pain. Learn C++ before learning Qt.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.