Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]How to generate build number?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]How to generate build number?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 12.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mbnoimi
    wrote on last edited by
    #1

    Hello,

    Usually I use "VERSION variable":http://qt-project.org/doc/qt-5/qmake-variable-reference.html#version for version my builds but unfortunately it needs manual modification whenever I need to create a new release so I need some number generated automatically whenever I build my applications (build number)

    Is there any way to generate a build number automatically instead of generating it manually (ex. using TIMEDATE functions of the operating system with "system function":http://qt-project.org/doc/qt-5/qmake-test-function-reference.html#system-command)?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbnoimi
      wrote on last edited by
      #2

      BTW, I "found this thread":http://qt-project.org/forums/viewthread/6908 but unfortunately it didn't help me out because the suggested solution didn't work!

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        You don't use any build system (for example: Jenkins), right?

        What you can do is to add a text file containing the last build number, and make your build process increment the number inside that file, and then compile it into your binary.

        How can you compile the build number into the binary?
        Pass something like this to qmake, and then use that variable in your source code:
        @
        DEFINES+="BUILDNUMBER=12345"
        @

        You have suggested using timestamps. This is a nice idea and is actually much easier. Datetime functions are part of C++ standard, so they are available on all platforms and compilers. Something like this should work:
        @
        QString compilationTime = QString("%1T%2").arg(DATE).arg(TIME);
        @

        You can also throw that data into a QDateTime to get a nice and consistent date format of your choice.

        (Z(:^

        1 Reply Last reply
        2
        • M Offline
          M Offline
          mbnoimi
          wrote on last edited by
          #4

          [quote]You have suggested using timestamps. This is a nice idea and is actually much easier. Datetime functions are part of C++ standard, so they are available on all platforms and compilers. Something like this should work:

          QString compilationTime = QString("%1T%2").arg(__DATE__).arg(__TIME__);
          

          You can also throw that data into a QDateTime to get a nice and consistent date format of your choice.[/quote]

          But the snippet you've suggested changes on run-time while I want a solution works only on build-time (prebuild)

          1 Reply Last reply
          0
          • Chris KawaC Online
            Chris KawaC Online
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by
            #5

            __DATE__ and __TIME__ are predefined compile-time macros, not functions evaluated at run-time. They will expand to a constant string literal with the compile-time values.
            One thing to remember when using them though, is that you need to make sure the file containing them is actually compiled when you build. If you don't they will have old values next time you link. Something like "touch" as a pre-build event will do the job. You can also do a full rebuild when you need them to update.

            1 Reply Last reply
            2
            • M Offline
              M Offline
              mbnoimi
              wrote on last edited by
              #6

              Thank you a lot guys (specially sierdzio); The solution is much easier than I expected.

              [code]QString build = QString("%1%2")
              .arg(QLocale(QLocale::C).toDate(QString(DATE).simplified(), QLatin1String("MMM d yyyy")).toString("yyyyMMdd"))
              .arg(QString("%1%2%3%4%5%6").arg(TIME[0])
              .arg(TIME[1])
              .arg(TIME[3])
              .arg(TIME[4])
              .arg(TIME[6])
              .arg(TIME[7]));[/code]

              The output: 20140505150357

              1 Reply Last reply
              0
              • M Offline
                M Offline
                MuldeR
                wrote on last edited by
                #7

                Side note: If you just want an automatically increasing build number rather than a time stamp (what you have now), you could be using my "AutoInc":https://github.com/lordmulder/LameXP/blob/master/etc/Utilities/AutoInc.exe utility. It will scan the specified header file for the specified macro and, if found, increase its value by one. There's also an optional timeout, so it won't be increased again, if the file was already updated recently.

                Another thing you should consider: If you are working with a revision control system (like Git or SVN), you could simply be counting the number of revisions (commits) and make that the build number. It's what x264 and friends do. The advantage is that your build numbers will always be "in sync" with the repository and each build number directly maps to a specific revision/commit. This is especially useful, if there are many developers on the project...

                My OpenSource software at: http://muldersoft.com/

                Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

                Go visit the coop: http://youtu.be/Jay...

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mbnoimi
                  wrote on last edited by
                  #8

                  [quote]Side note: If you just want an automatically increasing build number rather than a time stamp (what you have now), you could be using my AutoInc [github.com] utility[/quote]
                  Thank you; I found your tool before but for some reason it didn't work :( Any way; Time Stamp fits my need exactly.

                  [quote]Another thing you should consider: If you are working with a revision control system (like Git or SVN)[/quote]
                  Nice idea but I can't use it always because I don't versioning all my projects and most projects I work on use Bzr which somehow is going the die.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved