Results 1 to 17 of 17

Thread: QMAKE custom DEFINES & CONFIG

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QMAKE custom DEFINES & CONFIG

    Hi,

    I'm new to Qt and its qmake functions. I have read through the Qt Assistant but I do not comprehend everything yet.

    May I know how can we add custom DEFINES & CONFIG in the *.pro and *.pri files?

    E.g.

    Qt Code:
    1. win32 {
    2. }
    3. macx {
    4. }
    To copy to clipboard, switch view to plain text mode 

    If I need a class in Windows only, can I do a *pro file as below? However, it is not working as I expected.

    Qt Code:
    1. win32:DEFINES += WIN32_MYCLASS //(but not working also in qmake)
    2. win32:CONFIG += win32_myclass //(but not working in *.cpp during #ifdef #endif)
    To copy to clipboard, switch view to plain text mode 

    Please advice. Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QMAKE custom DEFINES & CONFIG

    If you want different versions of a file be included use:
    Qt Code:
    1. win32 {
    2. INCLUDE += Windows/myfile.h
    3. }
    4. macx {
    5. INCLUDE += Mac/myfile.h
    6. }
    To copy to clipboard, switch view to plain text mode 

    or for different code in one file use

    Qt Code:
    1. MyClass::whatEver()
    2. {
    3. #ifdef Q_OS_UNIX
    4. // do fancy unix stuff
    5. #endif
    6. #ifdef Q_OS_WIN32
    7. // do windows stuff here
    8. #endif
    9. }
    To copy to clipboard, switch view to plain text mode 

    The right code is chosen by the compiler automatically.

  3. #3
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMAKE custom DEFINES & CONFIG

    Thanks, Lykurg for your fast reply! I did understand the part on macx and win32 platform specific codes.

    But, what I mean is that how can I separate the C++ classes under single win32 platform?

    e.g.
    SimpleBuild (contains ClassA only)
    AdvancedBuild (contains ClassA, ClassB, and ClassC)

    I need to do different *pro file that uses different custom configuration to add files.

    Qt Code:
    1. win32:DEFINES += WIN32_ADVANCED
    2. win32:CONFIG += win32_Advanced
    3.  
    4. SUBDIRS += simple_build.pro
    To copy to clipboard, switch view to plain text mode 

    Under SUBDIRS there are WIN32_ADVANCED flags to check whether the class is needed or not.
    Then, under a controller class, there is a #ifdef win32_Advanced flag to include its header.

    Hope this clarify my query.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QMAKE custom DEFINES & CONFIG

    Ah, ok. Misread it the first time. Then I would suggest in your pro file:
    Qt Code:
    1. contains(DEFINES, WIN32_ADVANCED) {
    2. message(Building the advanced version...)
    3. }
    To copy to clipboard, switch view to plain text mode 

    with
    Qt Code:
    1. $qmake mypro.pro
    To copy to clipboard, switch view to plain text mode 
    build normal mode, and
    Qt Code:
    1. $qmake "DEFINES += WIN32_ADVANCED" mypro.pro
    To copy to clipboard, switch view to plain text mode 
    building the advanced.

    Hope you mean that

  5. The following user says thank you to Lykurg for this useful post:

    sheeeng (23rd April 2009)

  6. #5
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMAKE custom DEFINES & CONFIG

    Quote Originally Posted by Lykurg View Post
    Ah, ok. Misread it the first time. Then I would suggest in your pro file:
    Qt Code:
    1. contains(DEFINES, WIN32_ADVANCED) {
    2. message(Building the advanced version...)
    3. }
    To copy to clipboard, switch view to plain text mode 

    with
    Qt Code:
    1. $qmake mypro.pro
    To copy to clipboard, switch view to plain text mode 
    build normal mode, and
    Qt Code:
    1. $qmake "DEFINES += WIN32_ADVANCED" mypro.pro
    To copy to clipboard, switch view to plain text mode 
    building the advanced.

    Hope you mean that
    Before the contains, how do we add the WIN32_ADVANCED flag?

    How do we use that '$qmake" in *.pro file? I'm building using MSVC and opens the *.pro file using Qt-VSIntegration.

    Thanks!

  7. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QMAKE custom DEFINES & CONFIG

    Quote Originally Posted by sheeeng View Post
    Before the contains, how do we add the WIN32_ADVANCED flag?

    How do we use that '$qmake" in *.pro file? I'm building using MSVC and opens the *.pro file using Qt-VSIntegration.

    Thanks!
    was a little typo: should be
    Qt Code:
    1. $ qmake mypro.pro
    To copy to clipboard, switch view to plain text mode 
    and should be indicate - as I don't have thought someone really is using Windows - that that is to type in the console when you building the app. How To integrate it in MSVC I don't know. To be explicate: You set the WIN32_ADVANCED flag via the console when you building.

  8. #7
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMAKE custom DEFINES & CONFIG

    Thanks, Lykurg. However, I did not able to add the custom DEFINES and custom CONFIG succesfully.

  9. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QMAKE custom DEFINES & CONFIG

    Ok, here is a console output which I can't better clarify:
    Qt Code:
    1. lykurg@XXX:~/Dokumente$ cat test.pro
    2. # normal *.pro file here
    3. message(normal stuff)
    4.  
    5. contains(DEFINES, WIN32_ADVANCED) {
    6. message(WIN32_ADVANCED stuff here)
    7. }
    8.  
    9. lykurg@XXX:~/Dokumente$ qmake test.pro
    10. Project MESSAGE: normal stuff
    11.  
    12. lykurg@XXX:~/Dokumente$ qmake "DEFINES += WIN32_ADVANCED" test.pro
    13. Project MESSAGE: normal stuff
    14. Project MESSAGE: WIN32_ADVANCED stuff here
    15.  
    16. lykurg@XXX:~/Dokumente$
    To copy to clipboard, switch view to plain text mode 

  10. #9
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMAKE custom DEFINES & CONFIG

    Thanks Lykurg. I guess I have to convert output to Qt-Windows and then open using Qt-VsIntegration.

  11. #10
    Join Date
    Jan 2009
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QMAKE custom DEFINES & CONFIG

    I think I should rephrase my question...

    How to carry forward "DEFINES += WIN32_ADVANCED" to all *pro under SUBDIRS?

  12. #11
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QMAKE custom DEFINES & CONFIG

    global.pro
    Qt Code:
    1. TEMPLATE = subdirs
    2. SUBDIRS = testsub
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. qmake "DEFINES += WIN32_ADVANCED" global.pro
    To copy to clipboard, switch view to plain text mode 
    results in Makefile
    Qt Code:
    1. //..
    2. testsub/$(MAKEFILE):
    3. @$(CHK_DIR_EXISTS) testsub/ || $(MKDIR) testsub/
    4. cd testsub/ && $(QMAKE) testsub.pro -unix DEFINES\ +=\ WIN32_ADVANCED -o $(MAKEFILE)
    5. sub-testsub-qmake_all: FORCE
    6. @$(CHK_DIR_EXISTS) testsub/ || $(MKDIR) testsub/
    7. cd testsub/ && $(QMAKE) testsub.pro -unix DEFINES\ +=\ WIN32_ADVANCED -o $(MAKEFILE)
    8. //..
    To copy to clipboard, switch view to plain text mode 

    just fine

Similar Threads

  1. qmake sux a lot
    By singermornings in forum Qt Programming
    Replies: 6
    Last Post: 29th January 2009, 08:33
  2. qmake and CONFIG copy_dir_files
    By Vanir in forum Qt Programming
    Replies: 0
    Last Post: 25th February 2008, 14:56
  3. Adding custom defines when on debug build
    By chus in forum Qt Programming
    Replies: 2
    Last Post: 2nd March 2007, 11:38
  4. Custom action added to make by qmake
    By NTwoO in forum Qt Programming
    Replies: 2
    Last Post: 2nd March 2007, 10:17
  5. Compiling with Qmake/Make
    By VireX in forum Newbie
    Replies: 25
    Last Post: 22nd February 2007, 05:57

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
  •  
Qt is a trademark of The Qt Company.