Results 1 to 8 of 8

Thread: Getting VERSION from code?

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

    Default Getting VERSION from code?

    Is there any reasonable way to get the value of the .pro's VERSION? Perhaps some way to make qmake output a header file for it? It seems a bit of a waste to have my version in two places.

  2. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Getting VERSION from code?

    add a define directive to your pro file :
    DEFINES += _VERSION_=${VERSION}
    And then use the _VERSION_ macro (or whatever you named it) inside your code.
    Current Qt projects : QCodeEdit, RotiDeCode

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

    sdfisher (27th July 2007)

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

    Default Re: Getting VERSION from code?

    Huh. This doesn't seem to work with the Visual Studio generator. I get VERSION_NUMBER=${VERSION} (with ${VERSION} not expanded) as one of my defines.

    Edit: DEFINES += VERSION_NUMBER="$${VERSION}" seems to have worked, though. Thanks for the nudge in the right direction.

    Edit #2: Actually, that doesn't seem to work, either. It adds VERSION_NUMBER="1.2.0.1" to the defines, but that doesn't seem to actually work.
    Last edited by sdfisher; 27th July 2007 at 23:21.

  5. #4
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Getting VERSION from code?

    Quote Originally Posted by sdfisher View Post
    Huh. This doesn't seem to work with the Visual Studio generator. I get VERSION_NUMBER=${VERSION} (with ${VERSION} not expanded) as one of my defines.

    Edit: DEFINES += VERSION_NUMBER="$${VERSION}" seems to have worked, though. Thanks for the nudge in the right direction.

    Edit #2: Actually, that doesn't seem to work, either. It adds VERSION_NUMBER="1.2.0.1" to the defines, but that doesn't seem to actually work.
    I'm afraid I never used VS integration so I can barely suggest anything more... The thing is that dependencies are probably not set properly (i.e. files using this macro won't be automatically scheduled for compilation every time the macro changes...) so you may need a "rebuild all" (or whatever it is called) to get the version number actually taken into account by your code...
    Current Qt projects : QCodeEdit, RotiDeCode

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

    Default Re: Getting VERSION from code?

    I think it's just a limitation of VS (not the integration, but of VS itself). It's okay. I can use that technique on other platforms.

  7. #6
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Getting VERSION from code?

    Quote Originally Posted by sdfisher View Post
    I think it's just a limitation of VS (not the integration, but of VS itself)
    Well, I'd tend to think that it's actually a limitation of most, if not all, compilers... I'm willing to bet that no build system (may it be cmake, qmake, scons, ...) does such a smart dependency checking... Just rebuild all once you changed the version number or do a "dummy edit" in each file that rely on the version macro. Dummy edit means forcing the file to be saved, without really modifying it, which triggers dependency tracking of your build system, since most rely on time stamps and not file hash... It generally expands to typing a char then undo-ing the change and then saving...
    Current Qt projects : QCodeEdit, RotiDeCode

  8. #7
    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: Getting VERSION from code?

    Quote Originally Posted by sdfisher View Post
    Edit: DEFINES += VERSION_NUMBER="$${VERSION}" seems to have worked, though. Thanks for the nudge in the right direction.

    Edit #2: Actually, that doesn't seem to work, either. It adds VERSION_NUMBER="1.2.0.1" to the defines, but that doesn't seem to actually work.
    Does
    DEFINES += VERSION_NUMBER=\\\"$${VERSION}\\\"
    do what you want?
    J-P Nurmi

  9. The following user says thank you to jpn for this useful post:

    sdfisher (30th August 2007)

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

    Default Re: Getting VERSION from code?

    Yes, that worked. Thank you so much. I'd completely given up.

Similar Threads

  1. Distributing QT application for Mac OS
    By mb0 in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2007, 18:59
  2. Replies: 15
    Last Post: 21st April 2007, 17:46
  3. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 13:15
  4. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 00:49

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.