Results 1 to 8 of 8

Thread: How to Get SVN version code in qt pro file

  1. #1
    Join Date
    Aug 2013
    Posts
    27
    Thanks
    3

    Angry How to Get SVN version code in qt pro file

    Hi All,
    I want to update the svn code automaticly when build my program by this way:
    In my project's pro file, I add following code to get snv code, but it does not work.
    Qt Code:
    1. SVNVERSION = $$system(svn info -r HEAD ../ | sed -n "/Revision/p" | sed "s/[^0-9]//g")
    2. DEFINES += VER=$${SVNVERSION}
    To copy to clipboard, switch view to plain text mode 

    The define in the makefile is not correct:
    -DVER=Revision: -DQT_DLL -DQT

    I try the sed commad in command window, it works well:
    D:\Aic\FirmwareServer\QtProject>svn info -r HEAD ../ | sed -n "/Revision/p" | se
    d "s/[^0-9]//g"
    471

    Is there any suggestion to solve this problem?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to Get SVN version code in qt pro file

    Have you tried putting the shell command sequence into a scrip and calling that script instead?

    Cheers,
    _

  3. #3
    Join Date
    Aug 2013
    Posts
    27
    Thanks
    3

    Default Re: How to Get SVN version code in qt pro file

    anda_skoa, thank you for your reply.
    I try your idea. But the qmake return both command line and result of the bat file to me!
    In my pro file:
    Qt Code:
    1. SVNVERSION=$$system(GetSvnInfo.bat)
    2. DEFINES += VER=$${SVNVERSION}
    To copy to clipboard, switch view to plain text mode 

    command line in the bat file:
    Qt Code:
    1. svn info -r HEAD ../ | sed -n "/Revision/p" | sed "s/[^0-9]//g"
    To copy to clipboard, switch view to plain text mode 

    and output make file as bellow:
    -DVER=D:\Aic\FirmwareServer\QtProject\Trunck\AICMonitor> svn -Dinfo -D-r -DHEAD -D../ -D| -Dsed -D-n -D"/Revision/p" -D| -Dsed -D"s/[^0-9]//g" -D474
    474 is my svn number. But also get the command line of the bat file which I marked as red color.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to Get SVN version code in qt pro file

    You write bat file which usually indicates a Windows batch execution file, while your content looks like Unix shell tools.

    Are you sure the environment of the script is correct?

    If you run the script file, does it work?

    Cheers,
    _

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

    Default Re: How to Get SVN version code in qt pro file

    Qt Code:
    1. svn info -r HEAD ../ | sed -n "/Revision/p" | sed "s/[^0-9]//g"
    To copy to clipboard, switch view to plain text mode 
    As a side note, "svn info" displays information with (i think) system default locale, so this will work as long as you have english system.
    On my system displayed text is in polish, and therefore it doesn't contain the word "Revision" - could be a problem if you have an autobuild server setup in another country ( it happened to me ). More reliable and general version could be to use the "xml" formatting:
    Qt Code:
    1. svn info --xml
    To copy to clipboard, switch view to plain text mode 
    this will always output the info in english, and you can get the revision number via "revision=..." attribute.

  6. #6
    Join Date
    Aug 2013
    Posts
    27
    Thanks
    3

    Default Re: How to Get SVN version code in qt pro file

    Yes. the sed tools is installed in WIN-AVR2010 package.
    So the script can work on windows platform.

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

    Default Re: How to Get SVN version code in qt pro file

    The "^" character has a special meaning to the Windows shell, roughly the same as the backslash escape in C++ or bash shell. It looks like it is being consumed with the result that the command being executed is this:
    Qt Code:
    1. svn info -r HEAD ../ | sed -n "/Revision/p" | sed "s/[0-9]//g"
    To copy to clipboard, switch view to plain text mode 
    which gives the output you complain of by removing the digits. Try:
    Qt Code:
    1. SVNVERSION = $$system(svn info -r HEAD ../ | sed -n "/Revision/p" | sed "s/[^^0-9]//g")
    2. DEFINES += VER=$${SVNVERSION}
    To copy to clipboard, switch view to plain text mode 
    (which is only good on Windows).

    Depending on the Subversion command line utilities you have to work with:
    Qt Code:
    1. SVNVERSION = $$system(svnversion ../)
    To copy to clipboard, switch view to plain text mode 
    might also work for you.

    If you are using TortoiseSVN then it is possible to script this using its exposed objects.

    BTW: This will only extract the version when you run qmake, and not every time you build.
    Last edited by ChrisW67; 7th May 2014 at 04:22.

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

    Abel (7th May 2014)

  9. #8
    Join Date
    Aug 2013
    Posts
    27
    Thanks
    3

    Default Re: How to Get SVN version code in qt pro file

    ChrisW67, Thank you!
    It works!
    I know it only get version number once by only run qmake once. I just need a version code for the auto building task to track issues, so it is enough for my task.
    Also thank you for the svnversion command, it is easier to get version code than svn info + sed.


    Added after 4 minutes:


    --xml is another good ideal.
    Last edited by Abel; 7th May 2014 at 12:16.

Similar Threads

  1. Replies: 2
    Last Post: 13th June 2011, 15:29
  2. Change Qt version and code stop working
    By rmagro in forum Qt Programming
    Replies: 6
    Last Post: 28th September 2010, 20:02
  3. How to get File version size?
    By phillip_Qt in forum Qt Programming
    Replies: 1
    Last Post: 11th October 2007, 06:53
  4. Getting VERSION from code?
    By sdfisher in forum Qt Programming
    Replies: 7
    Last Post: 30th August 2007, 01:15
  5. Get version from a rc file?
    By fellobo in forum Qt Programming
    Replies: 3
    Last Post: 30th August 2006, 20:52

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.