zoukankan      html  css  js  c++  java
  • Qt通过SVN自动给EXE版本信息QtVersionInfo

    相关资料:
    https://blog.csdn.net/yousss/article/details/82218475 VS开发中自动版本号的设置-SubWCRev命令
    https://blog.csdn.net/foruok/article/details/22665353 Qt Creator自动使用svn源代码版本号编译
    https://blog.csdn.net/foruok/article/details/19920681 Windows下Qt for Android 编译安卓C语言可执行程序

    https://download.csdn.net/download/zhujianqiangqq/21572072     代码包下载

    实例:

    .pro(重点) 

     1 # 相关资料:
     2 # https://blog.csdn.net/yousss/article/details/82218475    VS开发中自动版本号的设置-SubWCRev命令
     3 # https://blog.csdn.net/foruok/article/details/22665353    Qt Creator自动使用svn源代码版本号编译
     4 # https://blog.csdn.net/foruok/article/details/19920681    Windows下Qt for Android 编译安卓C语言可执行程序
     5 # **************CMD命令*******************
     6 # SubWcRev "D:QtDemoQtVersionInfoQtVersionInfo" -f | findstr "Updated to revision"
     7 # SubWcRev "D:QtDemoQtVersionInfoQtVersionInfo" -f | findstr "Mixed revision range"
     8 # SubWcRev "D:QtDemoQtVersionInfoQtVersionInfo" -f | findstr "Last committed at revision"
     9 # SubWcRev.exe ../QtVersionInfo "../QtVersionInfo/version.temp.h" "../QtVersionInfo/version.h"
    10 # svn info --show-item last-changed-revision D:QtDemoQtVersionInfoQtVersionInfo
    11 # **************版本号说明*************************
    12 # MAJAR_NUMBER 为大版本号,当出现新旧版本无法兼容时,递增。(比如旧版本与服务器版本完全无法兼容。)
    13 # MINOR_NUMBER 为中版本号,当大版本号递增时,归零。否则,当增加新功能时,递增。
    14 # CHANGE_NUMBER 为小版本号,当大版本号或小版本号递增时,归零。否则,每次发布,递增。(一般是BUG修复、优化,遗漏等)
    15 # BUILD_NUMBER 为构建版本号,每次发布增加,但不一定每次+1,因为我们使用了提交次数统计来作为构建版本号的。
    16 
    17 QT       += core gui
    18 
    19 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    20 
    21 CONFIG += c++11
    22 
    23 # The following define makes your compiler emit warnings if you use
    24 # any Qt feature that has been marked deprecated (the exact warnings
    25 # depend on your compiler). Please consult the documentation of the
    26 # deprecated API in order to know how to port your code away from it.
    27 DEFINES += QT_DEPRECATED_WARNINGS
    28 
    29 # You can also make your code fail to compile if it uses deprecated APIs.
    30 # In order to do so, uncomment the following line.
    31 # You can also select to disable deprecated APIs only up to a certain version of Qt.
    32 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    33 
    34 SOURCES += 
    35     main.cpp 
    36     mainwindow.cpp
    37 
    38 HEADERS += 
    39     mainwindow.h 
    40     version.h
    41 
    42 FORMS += 
    43     mainwindow.ui
    44 
    45 
    46 # 如果含有中文,记得将pro文件的编码格式设置为GBK,否则中文将会是乱码
    47 # 版本号
    48 VERSION = 2.0.1.9
    49  QMAKE_TARGET_PRODUCT = 客户端
    50  QMAKE_TARGET_COMPANY = LWJR
    51  QMAKE_TARGET_DESCRIPTION = 数据空战应用程序
    52  QMAKE_TARGET_COPYRIGHT = Copyright @2020 LWJR,All rights reserved.
    53 # 本程序使用两个图标,这样其快捷方式可以有更多选择,也可以给关联文件提供图标选择
    54 RC_ICONS += icon1.ico 
    55             icon2.ico
    56 # 语言 0x0004 表示 简体中文
    57 # 详见 https://msdn.microsoft.com/en-us/library/dd318693%28vs.85%29.aspx
    58 RC_LANG = 0x0004
    59 
    60 
    61 # Default rules for deployment.
    62 qnx: target.path = /tmp/$${TARGET}/bin
    63 else: unix:!android: target.path = /opt/$${TARGET}/bin
    64 !isEmpty(target.path): INSTALLS += target
    View Code

     main.cpp

     1 #include "mainwindow.h"
     2 
     3 #include <QApplication>
     4 
     5 int main(int argc, char *argv[])
     6 {
     7     QApplication a(argc, argv);
     8     MainWindow w;
     9     w.show();
    10     return a.exec();
    11 }
    View Code

     mainwindow.h

     1 #ifndef MAINWINDOW_H
     2 #define MAINWINDOW_H
     3 
     4 #include <QMainWindow>
     5 
     6 QT_BEGIN_NAMESPACE
     7 namespace Ui { class MainWindow; }
     8 QT_END_NAMESPACE
     9 
    10 class MainWindow : public QMainWindow
    11 {
    12     Q_OBJECT
    13 
    14 public:
    15     MainWindow(QWidget *parent = nullptr);
    16     ~MainWindow();
    17 
    18 private slots:
    19     void on_pushButton_clicked();
    20 
    21 private:
    22     Ui::MainWindow *ui;
    23 };
    24 #endif // MAINWINDOW_H
    View Code

     mainwidow.cpp

     1 #include "mainwindow.h"
     2 #include "ui_mainwindow.h"
     3 #include <QDebug>
     4 
     5 MainWindow::MainWindow(QWidget *parent)
     6     : QMainWindow(parent)
     7     , ui(new Ui::MainWindow)
     8 {
     9     ui->setupUi(this);
    10 }
    11 
    12 MainWindow::~MainWindow()
    13 {
    14     delete ui;
    15 }
    16 
    17 
    18 void MainWindow::on_pushButton_clicked()
    19 {
    20 
    21 }
    View Code

     mainwidow.ui

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <ui version="4.0">
     3  <class>MainWindow</class>
     4  <widget class="QMainWindow" name="MainWindow">
     5   <property name="geometry">
     6    <rect>
     7     <x>0</x>
     8     <y>0</y>
     9     <width>419</width>
    10     <height>191</height>
    11    </rect>
    12   </property>
    13   <property name="windowTitle">
    14    <string>MainWindow</string>
    15   </property>
    16   <widget class="QWidget" name="centralwidget">
    17    <widget class="QLabel" name="label">
    18     <property name="geometry">
    19      <rect>
    20       <x>40</x>
    21       <y>40</y>
    22       <width>331</width>
    23       <height>21</height>
    24      </rect>
    25     </property>
    26     <property name="font">
    27      <font>
    28       <pointsize>15</pointsize>
    29       <weight>75</weight>
    30       <bold>true</bold>
    31      </font>
    32     </property>
    33     <property name="text">
    34      <string>通过SVN自动给EXE版本信息</string>
    35     </property>
    36    </widget>
    37   </widget>
    38  </widget>
    39  <resources/>
    40  <connections/>
    41 </ui>
    View Code

     resources呼略

    getSvnVersion.bat

    1 echo on
    2 SubWcRev.exe ../QtVersionInfo "../QtVersionInfo/QtVersionInfo.temp.pro" "../QtVersionInfo/QtVersionInfo.pro"
    View Code

    QtVersionInfo.temp.pro

     1 # 相关资料:
     2 # https://blog.csdn.net/yousss/article/details/82218475    VS开发中自动版本号的设置-SubWCRev命令
     3 # https://blog.csdn.net/foruok/article/details/22665353    Qt Creator自动使用svn源代码版本号编译
     4 # https://blog.csdn.net/foruok/article/details/19920681    Windows下Qt for Android 编译安卓C语言可执行程序
     5 # **************CMD命令*******************
     6 # SubWcRev "D:QtDemoQtVersionInfoQtVersionInfo" -f | findstr "Updated to revision"
     7 # SubWcRev "D:QtDemoQtVersionInfoQtVersionInfo" -f | findstr "Mixed revision range"
     8 # SubWcRev "D:QtDemoQtVersionInfoQtVersionInfo" -f | findstr "Last committed at revision"
     9 # SubWcRev.exe ../QtVersionInfo "../QtVersionInfo/version.temp.h" "../QtVersionInfo/version.h"
    10 # svn info --show-item last-changed-revision D:QtDemoQtVersionInfoQtVersionInfo
    11 # **************版本号说明*************************
    12 # MAJAR_NUMBER 为大版本号,当出现新旧版本无法兼容时,递增。(比如旧版本与服务器版本完全无法兼容。)
    13 # MINOR_NUMBER 为中版本号,当大版本号递增时,归零。否则,当增加新功能时,递增。
    14 # CHANGE_NUMBER 为小版本号,当大版本号或小版本号递增时,归零。否则,每次发布,递增。(一般是BUG修复、优化,遗漏等)
    15 # BUILD_NUMBER 为构建版本号,每次发布增加,但不一定每次+1,因为我们使用了提交次数统计来作为构建版本号的。
    16 
    17 QT       += core gui
    18 
    19 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    20 
    21 CONFIG += c++11
    22 
    23 # The following define makes your compiler emit warnings if you use
    24 # any Qt feature that has been marked deprecated (the exact warnings
    25 # depend on your compiler). Please consult the documentation of the
    26 # deprecated API in order to know how to port your code away from it.
    27 DEFINES += QT_DEPRECATED_WARNINGS
    28 
    29 # You can also make your code fail to compile if it uses deprecated APIs.
    30 # In order to do so, uncomment the following line.
    31 # You can also select to disable deprecated APIs only up to a certain version of Qt.
    32 #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    33 
    34 SOURCES += 
    35     main.cpp 
    36     mainwindow.cpp
    37 
    38 HEADERS += 
    39     mainwindow.h 
    40     version.h
    41 
    42 FORMS += 
    43     mainwindow.ui
    44 
    45 
    46 # 如果含有中文,记得将pro文件的编码格式设置为GBK,否则中文将会是乱码
    47 # 版本号
    48 VERSION = 2.0.1.$WCREV$
    49  QMAKE_TARGET_PRODUCT = 客户端
    50  QMAKE_TARGET_COMPANY = LWJR
    51  QMAKE_TARGET_DESCRIPTION = 数据空战应用程序
    52  QMAKE_TARGET_COPYRIGHT = Copyright @2020 LWJR,All rights reserved.
    53 # 本程序使用两个图标,这样其快捷方式可以有更多选择,也可以给关联文件提供图标选择
    54 RC_ICONS += icon1.ico 
    55             icon2.ico
    56 # 语言 0x0004 表示 简体中文
    57 # 详见 https://msdn.microsoft.com/en-us/library/dd318693%28vs.85%29.aspx
    58 RC_LANG = 0x0004
    59 
    60 
    61 # Default rules for deployment.
    62 qnx: target.path = /tmp/$${TARGET}/bin
    63 else: unix:!android: target.path = /opt/$${TARGET}/bin
    64 !isEmpty(target.path): INSTALLS += target
    View Code

     PS:

    getSvnVersion.bat需要在项目中增加一个编译项。方法:QT左侧->项目->Build步骤->添加Build步骤->Custom Process Step->Command:->"D:QtDemoQtVersionInfoQtVersionInfogetSvnVersion.bat"。

    PS:

    这个工程需要放在SVN管理里,要不然没有版本号。

    作者:疯狂Delphi
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.

    欢迎关注我,一起进步!扫描下方二维码即可加我

  • 相关阅读:
    .net core webapi 前后端开发分离后的配置和部署
    403
    Visual Studio提示“无法启动IIS Express Web服务器”的解决方法
    一件能让人没脸见人的事
    过程 sp_addextendedproperty, 对象无效。不允许有扩展属性,或对象不存在。
    处理程序“ExtensionlessUrlHandler-Integrated-4.0”在其模块列表中有一个错误模块“ManagedPipelineHandler”
    阿里ECS配置MSSQL远程连接的坑
    .Net Webapi SignalR与微信小程序的交互
    Entity Framework 异常: 'OFFSET' 附近有语法错误。 在 FETCH 语句中选项 NEXT 的用法无效。
    postgresql 表继承
  • 原文地址:https://www.cnblogs.com/FKdelphi/p/15190383.html
Copyright © 2011-2022 走看看