在Qt Creator中自动增加内部版本号 [英] Automatic increment of build number in Qt Creator

查看:667
本文介绍了在Qt Creator中自动增加内部版本号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在C ++源代码中有一个变量(或 #define ),每次我使用Qt Creator构建源代码时都会递增。有什么办法,我可以做到这一点,也许一些Qt Creator插件或类似的?如果我有一个方法来做,如果我在命令行使用make来构建?

I would like to have a variable (or #define) in C++ source that will increment each time I use Qt Creator to build source code. Is there any way I can do this, perhaps some Qt Creator plugin or similar? If there is a way to do it if I use "make" on command line to build?

推荐答案

,您可以创建一个包含命令行程序结果的变量。您可以使用它来创建一个定义。

In your .pro file, you can create a variable that contains the results of a command-line program. You can then use that to create a define.

BUILDNO = $$(command_to_get_the_build_number)
DEFINES += BUILD=$${BUILDNO}

如果您只想要一个简单的递增数字, :

If you just want a simple incrementing number, you could use a pretty simple script:

#!/bin/bash
number=`cat build_number`
let number += 1
echo "$number" | tee build_number #<-- output and save the number back to file

导致构建号在每次构建时递增,并且如果您尝试构建但是递增,但它失败。一个更好的方法是根据代码的状态获取一个内部版本号,许多版本控制工具可以给你一个文本字符串,如果不是一个数字。

I should note that this would cause the build number to increment every time you build, and also increment if you try to build but it fails. A better way is to get a build number based on the state of the code, and many version control tools can get you a text string for that, if not a number.

这篇关于在Qt Creator中自动增加内部版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆