Results 1 to 4 of 4

Thread: Qt usage macro

  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Qt usage macro

    Hello!

    I'ld like to know if there is a macro that is defined always when Qt is used in a project/file. I mean, if a #include <QtSomething> is used in a .h or .cpp, is there a macro that it's automatically defined/set to true so one could identify in the code if Qt is being used or not?


    To give some context, I'm creating a .h with a set of general defines that I'ld like to use in a standarized form in my applications, some of which may not actually include Qt. Since some of the definitions I'm including in my .h requires Qt to be included, I'ld like to put them inside a macro that will only 'activate' them if Qt is being used:

    Qt Code:
    1. //.h
    2.  
    3. #if QT_IS_USED
    4.  
    5. #define xxxx
    6. #define yyy
    7.  
    8. #endif
    To copy to clipboard, switch view to plain text mode 


    Thanks,

    Momergil

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt usage macro

    QT_VERSION, or pretty much anything from QtGlobal. However, this sort of environment detection is often done outside the program being built by a configure script that sets flags of your choosing if Qt is present and the user has not disabled it.

  3. The following user says thank you to ChrisW67 for this useful post:

    Momergil (15th July 2013)

  4. #3
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt usage macro

    Quote Originally Posted by ChrisW67 View Post
    QT_VERSION, or pretty much anything from QtGlobal. However, this sort of environment detection is often done outside the program being built by a configure script that sets flags of your choosing if Qt is present and the user has not disabled it.
    Hmm, I thought about this possibility... It would be, in this case, something like "#if QT_VERSION > 0x000000"?

    Now about what you explained regarding using configuration scripts, I'm not sure I understood the proceeding, but still I see no reason about how could I do that given my context (the header file I'm creating).
    Last edited by Momergil; 15th July 2013 at 04:26.

  5. #4
    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: Qt usage macro

    Quote Originally Posted by Momergil View Post
    It would be, in this case, something like "#if QT_VERSION > 0x000000"?
    Qt Code:
    1. #ifdef QT_VERSION
    To copy to clipboard, switch view to plain text mode 
    is enough unless somebody else (rather than Qt) introduces such define.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    Momergil (17th July 2013)

Similar Threads

  1. Including Q_OBJECT in another macro
    By Thuan Seah Tan in forum Qt Programming
    Replies: 1
    Last Post: 14th March 2012, 05:21
  2. Q_OBJECT macro problem
    By bijan311 in forum Newbie
    Replies: 46
    Last Post: 26th March 2010, 22:21
  3. Q_OBJECT macro - what exactly does it do?
    By magland in forum Qt Programming
    Replies: 3
    Last Post: 26th September 2007, 10:30
  4. Macro
    By comlink21 in forum Qt Programming
    Replies: 1
    Last Post: 25th July 2007, 11:28
  5. Macro used for debugging
    By sunil.thaha in forum General Programming
    Replies: 11
    Last Post: 30th March 2007, 17:32

Tags for this Thread

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.