Search code examples
c++qtqmake

Qt Version Incrementing


I am using a batch file to increment the last version number. I set it up to a variable in the .pro file, then in my main.cpp I try setting a Qstring to a version number and then using QDebug to see if the number is right. So far the batch file is not being called and the last args when setting QString to the version number is "too few" with a warning message.

The .pro file having the problems:

VERSION_MAJOR = 1
VERSION_MINOR = 0
VERSION_BUILD = $$(autoincrement.bat)

VERSION = $${VERSION_MAJOR}.$${VERSION_MINOR}.$${VERSION_BUILD}

DEFINES += "VERSION_MAJOR=$$VERSION_MAJOR"\
       "VERSION_MINOR=$$VERSION_MINOR"\
       "VERSION_BUILD=$${VERSION_BUILD}"

main.cpp

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QString version = QString("%1.%2.%3").arg(VERSION_MAJOR)
            .arg(VERSION_MINOR).arg(VERSION_BUILD);
    QApplication::setApplicationVersion(version);
    qDebug() << version;
    NewsBulletin w;
    w.show();

    return a.exec();
}

Solution

  • Here is my solution to iterating for each build for Windows (definitely prefer Bash):

    1. Create a version.bat containing:

      @echo off 
      set /p var= <version.txt 
      set /a var= %var%+1 
      echo %var% >version.txt
      break >version.h
      echo #define VERSION_MAJOR 1 >version.h
      echo #define VERSION_MINOR 0 >>version.h
      echo #define VERSION_BUILD %var% >>version.h
      echo %var%
      

      Run it once to create the other files.

    2. Next, go to projects in qt and add a build step to debug and run.
    3. Put the batch file in the command, and go to the .pro folder where the batch is in the working directory.
    4. Next, add the version.h file to the project.
    5. Finally, you have to include version.h in each file you want to use the version numbers.