Results 1 to 4 of 4

Thread: qmake rc file define version

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Posts
    56
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default qmake rc file define version

    Default Re: QMake DEFINES

    Hi there,

    How is it possible to define the FILEVERSION (without the quotes) For the VERSIONINFO struct in the resource file(windows),
    something like this:

    DEFINES+= PROD_VER=5,6,4,5


    thanks for the help...

    Cafu

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: qmake rc file define version

    You can have separate file with all defines, which you can include in .rc file. Here is an example:
    Qt Code:
    1. // program_strings.h
    2. #ifndef _STRINGS_H_
    3. #define _STRINGS_H_
    4.  
    5. #define _STR_COMPANY_NAME "My Company Name"
    6. #define _STR_PRODUCT_NAME "ProgramName"
    7. #define _PRODUCT_VERSION 3,4,0,0
    8. #define _STR_PRODUCT_VERSION "3.4"
    9. #define _STR_FILE_DESCRIPTION "Short description of the program"
    10. #define _FILE_VERSION 3,4,1234,0
    11. #define _STR_FILE_VERSION "3,4,1234,0"
    12. #define _STR_INTERNAL_NAME "ProgramName"
    13. #define _STR_LEGAL_COPYRIGHT "Copyright © ..."
    14. #define _STR_LEGAL_TRADE_1 "All rights reserved or something"
    15. #define _STR_LEGAL_TRADE_2 _STR_LEGAL_TRADE_1
    16. #define _STR_ORIGINAL_FILE_NAME "Program.exe"
    17. #define _STR_WEBSITE "www.mywebsite.com"
    18.  
    19. #endif /* _STRINGS_H_ */
    20.  
    21.  
    22. // program.rc
    23.  
    24. IDI_ICON1 ICON DISCARDABLE "your icon.ico"
    25.  
    26. #include <windows.h>
    27. #include "program_strings.h"
    28.  
    29. VS_VERSION_INFO VERSIONINFO
    30. FILEVERSION _FILE_VERSION
    31. PRODUCTVERSION _PRODUCT_VERSION
    32. BEGIN
    33. BLOCK "StringFileInfo"
    34. BEGIN
    35. BLOCK "040904E4"
    36. BEGIN
    37. VALUE "CompanyName", _STR_COMPANY_NAME
    38. VALUE "FileDescription", _STR_FILE_DESCRIPTION
    39. VALUE "FileVersion", _STR_FILE_VERSION
    40. VALUE "InternalName", _STR_INTERNAL_NAME
    41. VALUE "LegalCopyright", _STR_LEGAL_COPYRIGHT
    42. VALUE "LegalTrademarks1", _STR_LEGAL_TRADE_1
    43. VALUE "OriginalFilename", _STR_ORIGINAL_FILE_NAME
    44. VALUE "ProductName", _STR_PRODUCT_NAME
    45. VALUE "ProductVersion", _STR_PRODUCT_VERSION
    46. END
    47. END
    48. END
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    May 2009
    Posts
    56
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qmake rc file define version

    Yeah i know i can do this but i wanted to do it in .pro file so the definition is available in the project as well, and i could use it within the code not just in the rc file. so i decide to do it like this
    /*pro file*/
    RELEASE=3
    DEFINES += "RELEASE_RC=$${RELEASE}"
    MAJOR=3
    DEFINES += "MAJOR_RC=$${MAJOR}"
    MINOR=3
    DEFINES += "MINOR_RC=$${MINOR}"
    PATCH=3
    DEFINES += "PATCH_RC=$${PATCH}"

    /*rc file*/
    #define PRODUCT_VERSION_RC RELEASE_RC,MAJOR_RC,MINOR_RC,PATCH_RC

    Thanks for the help
    Last edited by cafu1007; 30th March 2011 at 11:11.

  4. #4

    Default Re: qmake rc file define version

    I had this problem and solved it this way. A bit of a fiddle but it works, recording the version and the svn number in the .rc file and its available in the .cpp files too.

    1. Create a .pri file where the version number is set and use this in all the projects with a line
      Qt Code:
      1. include(../product_version.pri)
      To copy to clipboard, switch view to plain text mode 
    2. Create a header file with macros to handle the version number.
    3. Use the macros in your c++ code with a line
      Qt Code:
      1. #include "../product_version.h"
      To copy to clipboard, switch view to plain text mode 
    4. Use the macros within your .rc file with a line
      Qt Code:
      1. #include "../product_version.h"
      To copy to clipboard, switch view to plain text mode 


    The .pri file contains this:
    Qt Code:
    1. # Product version. Comma delimit 4 numbers eg. NW_VERSION=1,2,3,4
    2. NW_VERSION=3,0,652,0
    3. DEFINES += "VERSION_RC=$${NW_VERSION}"
    4. NW_SVN = $$system(svnversion -n)
    5. DEFINES += "SVN_RC=$${NW_SVN}"
    6. # Display the SVN version number in the build log
    7. QMAKE_PRE_LINK += @echo. & @echo "SVN version:" $$NW_SVN &
    To copy to clipboard, switch view to plain text mode 

    1. Sets a qmake variable to the 4-digit version number
    2. Sets the value of this as a #define that gets passed to the compiler as
      Qt Code:
      1. #define VERSION_RC 1,2,3,4
      To copy to clipboard, switch view to plain text mode 
    3. Runs subversion and sets its returned value into another qmake variable and passed to the compiler in similar fashion
    4. Finally echos the SVN version into the log with a line break to make it stand out.


    The header file contains this:
    Qt Code:
    1. /* We expect declarations VERSION_RC=1,2,3,4 and SVN_RC=4123:4168MS
    2.   to have been set in the .pro script using the DEFINES command.
    3.  */
    4. #define MAKESTRING(x) #x
    5. #ifdef _MSC_VER
    6. // Visual studio mangles the standard macro PRODUCT_VERSION_STRING by expanding it to:
    7. // "3,0,652,0" "," "," "," " - " "799:800M"
    8. // So we use this alternative.
    9. #define EXPANDMACROx4(y) MAKESTRING(y)
    10.  
    11. #else
    12.  
    13. #define VERSIONSTRING(a,b,c,d) MAKESTRING(a) "," MAKESTRING(b) "," MAKESTRING(c) "," MAKESTRING(d)
    14. #define EXPANDMACROx4(y) VERSIONSTRING(y)
    15.  
    16. #endif
    17.  
    18. #define EXPANDMACROx1(y) MAKESTRING(y)
    19. #define FILE_VERSION_STRING EXPANDMACROx4(VERSION_RC)
    20. #define JOIN_STRINGS(a,b) a " - " EXPANDMACROx1(b)
    21. #define PRODUCT_VERSION_STRING JOIN_STRINGS(FILE_VERSION_STRING,SVN_RC)
    To copy to clipboard, switch view to plain text mode 

    I'm not going to attempt to explain the above, it works by trial and lots of error.

    In your source you can have this for example:
    Qt Code:
    1. m_logo->setToolTip(QString(PRODUCT_VERSION_STRING));
    To copy to clipboard, switch view to plain text mode 

    In your .rc file you can have this for example:
    Qt Code:
    1. #include "../product_version.h"
    2.  
    3. VS_VERSION_INFO VERSIONINFO
    4. FILEVERSION VERSION_RC
    5. PRODUCTVERSION VERSION_RC
    6. FILEFLAGSMASK 0x3fL
    7. #ifdef _DEBUG
    8. FILEFLAGS VS_FF_DEBUG
    9. #else
    10. FILEFLAGS 0x0L
    11. #endif
    12. FILEOS VOS__WINDOWS32
    13. FILETYPE VFT_DLL
    14. FILESUBTYPE 0x0L
    15. BEGIN
    16. BLOCK "StringFileInfo"
    17. BEGIN
    18. BLOCK "080904B0"
    19. BEGIN
    20. VALUE "CompanyName", "ABC Systems"
    21. VALUE "FileDescription", "ABC application"
    22. VALUE "FileVersion", FILE_VERSION_STRING
    23. VALUE "LegalCopyright", "© ABC Limited. All rights reserved."
    24. VALUE "OriginalFilename", "abc.exe"
    25. VALUE "ProductName", "Abc"
    26. VALUE "ProductVersion", PRODUCT_VERSION_STRING
    27. END
    28. END
    29. BLOCK "VarFileInfo"
    30. BEGIN
    31. VALUE "Translation", 0x809, 1200
    32. END
    33. END
    To copy to clipboard, switch view to plain text mode 

    Don't forget the other gotchas:
    • In your project file you'll need:
      Qt Code:
      1. RC_FILE += product.rc
      To copy to clipboard, switch view to plain text mode 
    • If you use Visual Studio then you will also need:
      Qt Code:
      1. QMAKE_RC = rc -D_MSC_VER
      To copy to clipboard, switch view to plain text mode 


    I think thats all. Good luck!

Similar Threads

  1. How to define a string marco in pro file
    By jevonwang in forum Qt for Embedded and Mobile
    Replies: 5
    Last Post: 6th May 2013, 05:49
  2. Replies: 2
    Last Post: 17th October 2010, 17:20
  3. Replies: 2
    Last Post: 7th October 2010, 02:05
  4. Replies: 1
    Last Post: 3rd December 2009, 23:34
  5. Define compiler in qmake
    By philski in forum Newbie
    Replies: 3
    Last Post: 24th April 2006, 21:47

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.