Results 1 to 8 of 8

Thread: How to know if the build is with Qt

  1. #1
    Join Date
    Aug 2006
    Posts
    77
    Thanks
    14
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default How to know if the build is with Qt

    Hi!

    I need to define different variables if the project is built with Qt.
    How could i define for example:

    #ifdef QtBuild

    ......
    .....

    #else

    .........

    #endif

    Thanks for the help.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to know if the build is with Qt

    How about passing your own compiler define?

    I'm not exactly sure if there's any common compiler preprocessor macro defined in each and every Qt project. Most of the useful defines are defined in <QtGlobal> which you presumably don't want to include to a non-Qt project.
    J-P Nurmi

  3. #3
    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: How to know if the build is with Qt

    How about using "#ifdef QT_VERSION" ?

  4. #4
    Join Date
    Feb 2007
    Posts
    27
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How to know if the build is with Qt

    QT_VERSION is defined by QtGlobal, so I don't think you can do anything based on that. However, I believe you'll find that Qt defines preprocessor symbols for the various libraries you use, so for example you could use QT_CORE_LIB.

    #ifdef QT_CORE_LIB
    #include <QtGlobal>
    #endif
    // now QT_VERSION is defined

  5. #5
    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: How to know if the build is with Qt

    Quote Originally Posted by sdfisher View Post
    QT_VERSION is defined by QtGlobal, so I don't think you can do anything based on that.
    I don't really see a problem... If the macro is NOT defined, you know you're NOT using Qt files when compiling this module. Of course if you want to do somehing in a file which doesn't include anything "Qt-ish" but is consolidated with Qt code later on then relying on QtGlobal is not possible. But relying on other Qt-defined macros is possible only when qmake is informed it is to use Qt with the project. So you can't rely on it when compiling (for example) some libraries or modules which will then be used by a Qt-based project. The best choice really is to do what J-P suggested - use a custom macro of your own.

  6. #6
    Join Date
    Feb 2007
    Posts
    27
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How to know if the build is with Qt

    The question was "I need to define different variables if the project is built with Qt."

    Part of the problem is defining what "built with Qt" means. I took it at face value, which is to say built with qmake. Do Makefiles generated with qmake define QT_CORE_LIB? If so, you can detect Qt's building system that way. If not, I agree it's useless.

  7. #7
    Join Date
    Aug 2006
    Posts
    77
    Thanks
    14
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to know if the build is with Qt

    Hi to all!

    Yes I mean a project generated with qmake.
    Thanks for the help.

  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: How to know if the build is with Qt

    Quote Originally Posted by sdfisher View Post
    Do Makefiles generated with qmake define QT_CORE_LIB? If so, you can detect Qt's building system that way.
    They do, unless you tell qmake not to use Qt (CONFIG-=qt afair).

Similar Threads

  1. show build date in about box
    By glocker50 in forum Qt Programming
    Replies: 12
    Last Post: 3rd May 2015, 22:14
  2. QT4 build debian/ubuntu package 4.2
    By patrik08 in forum Installation and Deployment
    Replies: 3
    Last Post: 21st September 2006, 08:01
  3. Using qmake to build multiple apps and libs
    By marchand in forum Newbie
    Replies: 2
    Last Post: 12th June 2006, 17:33
  4. QMAKE: Specifying Build Dependencies
    By JohnSuykerbuyk in forum Qt Programming
    Replies: 1
    Last Post: 5th May 2006, 09:46
  5. How can I build <<hello world>> example statically
    By krivenok in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2006, 15:25

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.