QT安装程序制作

1 安装Qt installerframework

    从QT官网的http://download.qt.io/official_releases/qt-installer-framework/下载qt installer framework安装程序进行安装。

2 配置安装文件

1、建立安装程序制作目录,例如:d:\myapp_setup。

2、把Qt installer framework示例examples\tutorial目录下的config和packages两个目录拷贝到myapp_setup目录内。把应用程序的可执行文件和资源文件拷贝到myapp_setup\packages\com.vendor.product\data目录内。

3、修改配置文件config.xml

修改myapp_setup\setup\config目录内的config.xml文件。原文件为:

<?xml version="1.0"encoding="UTF-8"?>
<Installer>
   <Name>Your application</Name>
   <Version>1.0.0</Version>
   <Title>Your application Installer</Title>
   <Publisher>Your vendor</Publisher>
   <StartMenuDir>Super App</StartMenuDir>
   <TargetDir>@HomeDir@/InstallationDirectory</TargetDir>
</Installer>

各配置项描述如下:

<?xml version="1.0"encoding="UTF-8"?>

<Installer>

   <Name>你的应用程序名称</Name>

   <Version>程序版本</Version>

   <Title>安装向导名称</Title>

   <Publisher>版权所有方名称</Publisher>

   <StartMenuDir>开始菜单的名称</StartMenuDir>

   <TargetDir>缺省的指定安装目录</TargetDir>

</Installer>

修改后内容如下:

<?xml version="1.0"encoding="UTF-8"?>

<Installer>

   <Name>hvplayer</Name>

   <Version>1.18.01.15</Version>

    <Title>hvplayer安装</Title>

   <Publisher>hujianfeng</Publisher>

   <StartMenuDir>hvplayer</StartMenuDir>

   <TargetDir>@rootDir@/Program Files(x86)/hvplayer</TargetDir>

</Installer>

4、修改包信息文件packages.xml

修改myapp_setup\packages\com.vendor.product\meta\packages.xml文件。原文件如下:

<?xml version="1.0"encoding="UTF-8"?>

<Package>

   <DisplayName>The root component</DisplayName>

   <Description>Install this example.</Description>

   <Version>0.1.0-1</Version>

   <ReleaseDate>2010-09-21</ReleaseDate>

    <Licenses>

       <License name="Beer Public License Agreement"file="license.txt" />

   </Licenses>

   <Default>script</Default>

   <Script>installscript.qs</Script>

   <UserInterfaces>

       <UserInterface>page.ui</UserInterface>

   </UserInterfaces>

</Package>

各配置项描述如下:

<?xml version="1.0"encoding="UTF-8"?>

<Package>

   <DisplayName>安装组件名称</DisplayName>

   <Description>安装组件描述.</Description>

   <Version>版本</Version>

   <ReleaseDate>建立日期</ReleaseDate>

   <Licenses>

       <License name="许可协议文件" file="license.txt" />

   </Licenses>

   <Default>安装脚本文件</Default>

   <Script>installscript.qs</Script>

   <UserInterfaces>

       <UserInterface>安装界面定义文件page.ui</UserInterface>

   </UserInterfaces>

</Package>

修改后内容如下:

<?xml version="1.0"encoding="UTF-8"?>

<Package>

   <DisplayName>hvplayer</DisplayName>

   <Description>hvplayer视频播放器</Description>

   <Version>1.18.01.15</Version>

   <ReleaseDate>2018-01-15</ReleaseDate>

   <Licenses>

       <License name="General Public License v3"file="license.txt" />

    </Licenses>

   <Default>script</Default>

   <Script>installscript.qs</Script>

</Package>

5、修改安装脚本

修改myapp_setup\packages\com.vendor.product\meta目录下的installscript.qs,原文件如下:

function Component()
{
    //constructor
   component.loaded.connect(this, Component.prototype.loaded);

    if(!installer.addWizardPage(component, "Page",QInstaller.TargetDirectory))

       console.log("Could not add the dynamic page.");

}

Component.prototype.isDefault = function()
{
    // selectthe component by default
    returntrue;
}

Component.prototype.createOperations = function()
{
    try {
        //call the base create operations function
       component.createOperations();
    } catch(e) {
       console.log(e);
    }
} 

Component.prototype.loaded = function ()

{

    var page= gui.pageByObjectName("DynamicPage");

    if (page!= null) {

       console.log("Connecting the dynamic page entered signal.");

       page.entered.connect(Component.prototype.dynamicPageEntered);

    }

}

 

Component.prototype.dynamicPageEntered = function()

{

    varpageWidget = gui.pageWidgetByObjectName("DynamicPage");

    if(pageWidget != null) {

       console.log("Setting the widgets label text.")

       pageWidget.m_pageLabel.text = "This is a dynamically createdpage.";

    }

}


这里只简单修改Component.prototype.createOperations= function()函数,修改后内容如下:

Component.prototype.createOperations = function()
{
    try {
        //call the base create operations function
       component.createOperations();            
            if(systemInfo.productType === "windows") {
                component.addOperation("CreateShortcut","@TargetDir@/hvplayer.exe", "@StartMenuDir@/hvplayer.lnk");
               component.addOperation("CreateShortcut","@TargetDir@/hvplayer.exe","@HomeDir@/Desktop/hvplayer.lnk");
               component.addOperation("CreateShortcut","@TargetDir@/maintenancetool.exe", "@StartMenuDir@/更新或卸载.lnk");
           }
    } catch(e) {
       console.log(e);
    }
}

3 拷贝包安装依赖文件

在qt开始菜单下打开相应环境的命令行,执行:

windeployqt.exe D:\myapp_setup\packages\com.vendor.product\data

Windeployqt工具将把所有依赖文件拷贝到可执行文件所在的目录。

4 生成安装包

1、把Qt installer framework安装目录的bin目录加入系统的path环境变量。

2、打开命令行终端,进入myapp_setup目录,运行binarycreator.exe命令。

binarycreator.exe -c config\config.xml -p packagessetup.exe

Binarycreator工具将在myapp_setup目录内生成setup.exe安装文件。

下面是我生成的一个视频播放器示例:


 

 

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值