Qt is packaged into a setup.exe installation package

Qt is packaged into a setup.exe installation package

1. Brief introduction

After the development of the Qt project is completed, the release program needs to be packaged, and because there is no Qt configuration environment on the user's computer, it is necessary to copy the exe file generated by release and the dependent dll files to a folder, and then use the Inno Setup packaging tool to package It can be released into an exe installation package .

Second, set the application icon

The icon of the exe file we compiled and generated is a white box that comes with Qt, which is not very good-looking. How can we set the icon of the program by ourselves. First create a file in ico format. There are many online that can convert png or jpg pictures into icon files in ico format, and then put the ico file in the source code directory, which is the same folder as the .pro file. As shown below:

insert image description here

In the .pro project file add:

RC_ICONS = music.ico // 这里的music.ico是我的ico文件的名字,改成你自己的ico文件名

After adding, be sure to re-qmake again, and then run your program again, so look at the exe file in your debug or release folder, there will be the icon you set.

3. Release procedure

At present, the computer is win10 64-bit. The following operations use the 32-bit Qt compiler. The 64-bit compiler has been tried and cannot be successful.

The publishing program must first obtain the dependent dll files. There are two methods here. The first method is to go to the bin directory of the Qt installation directory (the author here is H:\Qtcreator\Qtcreator\5.12.9\mingw73_32) to find the dependent dll files. The second method is to use windeployqt.exe, the publishing tool that comes with Qt, to generate the dependent dll files. Here we focus on the second method. The steps are as follows:

(1) Compile and generate the exe program in Release mode , that is, select Release in the mode of debugging and running .

insert image description here

After successful operation, if "shadow build" is checked to separate the source code path from the build path, the exe file will be generated in the build-music-Desktop_Qt_5_12_9_MinGW_32_bit-Release folder , as shown in Figure 1 below; otherwise, the exe file will be generated in the source code project directory. The exe file is generated in the release folder , as shown in Figure 2 below.

insert image description here

insert image description here

Copy the music.exe executable file to another folder, here I copy it to H:\QMusic, and then find "Qt 5.12.9(MinGW 7.3.0 32-bit) under "Start Menu Qt5.12.9" " to run the file, open the run.

insert image description here

Execute the cd H:\QMusiccommand to enter the directory where the exe file is located, then execute the dircommand to view the directory, and finally execute the windeployqt cleanRobot.execommand , Qt will automatically copy all the dlls required by the program.

insert image description here

Of course, there may be some dlls that we do not need, such as the following D3Dcompiler_47.dll, in order to make the publishing program as small as possible, we can delete these dlls one by one, and then open the exe program to see which dlls are deleted and then open If the program is not available, keep it, and delete the rest.

Then copy the built-in folders, such as the image folder and myMusic folder in the figure below, delete unnecessary dlls, and the exe installation package folder is shown in the figure below.

insert image description here

In fact, at this step, the entire folder can be released, but if you want to package it into an exe installation package, you must perform the following steps.

Fourth, the packaging program

Inno Setup is a free Windows installer creation software. Small, simple and exquisite are its biggest features, support pascal script, can quickly create a standard Windows2000 style installation interface, enough to complete general installation tasks.

Official download address: http://www.jrsoftware.org/isdl.php#stable

You can install it directly after downloading.

After the development of the project is completed, the package program needs to be released, and the Inno Setup software can be used to make the installation exe. The following details how to package the application:

(1) Open Inno Setup Compiler, click [file] → [new], create a new script wizard, and then click [next];

insert image description here

(2) Enter "application name", "application version", "application publisher", "application website" in the application information, these information will be automatically generated in the script, and then click next;

insert image description here

(3) Fill in the default path and folder name of the package file during installation, and then click Next;

insert image description here

(4) Select the main executable file of the application, that is, the exe file you compiled and generated, click "Add folder" below, put all the dlls, resources and configuration files that your program needs to run in a folder, select this folder, and then click Next;

insert image description here

Note: Add folder is the parent folder for adding .exe, which includes all dependent dll and other files.

(5) Then click Next again by default to come to the following interface. Enter the name of the application displayed in the start menu, which functions are required, and tick the front, which is usually the default, and then click Next;

insert image description here

(6) Here you can choose "license file", "file before installation" (such as Readme file, etc.), "display information after installation", etc., and then click Next;

(7) Then click next by default again to come to the following interface. Select "Installation Language" and click Next;

insert image description here

(8) Select "Custom Compiler Output Folder", "Compiler Output Basic File Name", "Custom Installer Icon File" and "Installation Password", and then click Next;

insert image description here

9) Choose whether to use the #define compilation command here, choose yes, that is, use the #define macro to define some constants in the generated script, which is convenient for script writing, check if you want, and then click Next;

insert image description here

insert image description here

After clicking finish in the last step, you will be asked if you want to compile the new script immediately. We always click yes by default. This script is automatically generated based on the content we filled in earlier. You can use the compiler directly, or you can rewrite it yourself. The generated script code is posted below.

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "QMusic"
#define MyAppVersion "1.0"
#define MyAppExeName "music.exe"
#define MyAppAssocName MyAppName + " File"
#define MyAppAssocExt ".myp"
#define MyAppAssocKey StringChange(MyAppAssocName, " ", "") + MyAppAssocExt

[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={
    
    {
    
    D7AE9662-51F1-4698-9E39-97DEA943C371}
AppName={
    
    #MyAppName}
AppVersion={
    
    #MyAppVersion}
;AppVerName={
    
    #MyAppName} {
    
    #MyAppVersion}
DefaultDirName=H:/exe_file
ChangesAssociations=yes
DefaultGroupName={
    
    #MyAppName}
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
OutputDir=H:\exe_file
OutputBaseFilename=music
Password=123456
Compression=lzma
SolidCompression=yes
WizardStyle=modern

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "H:\QMusic\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
Source: "H:\QMusic\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Registry]
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocExt}\OpenWithProgids"; ValueType: string; ValueName: "{#MyAppAssocKey}"; ValueData: ""; Flags: uninsdeletevalue
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}"; ValueType: string; ValueName: ""; ValueData: "{#MyAppAssocName}"; Flags: uninsdeletekey
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\{#MyAppExeName},0"
Root: HKA; Subkey: "Software\Classes\{#MyAppAssocKey}\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\{#MyAppExeName}"" ""%1"""
Root: HKA; Subkey: "Software\Classes\Applications\{#MyAppExeName}\SupportedTypes"; ValueType: string; ValueName: ".myp"; ValueData: ""

[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon

[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
  • An error occurs during operation, which can be modified directly in the script.
  • If you want to package a new version of the exe installation package file, you don't need to go through the above process again, just replace the original exe executable file, and then open the originally generated script file to run (run the script on the inno setup Compiler software). file) to generate a new version of the exe installation package file.

Finally, the exe installation package file is generated, click to open the exe file to install,

Guess you like

Origin blog.csdn.net/weixin_44069765/article/details/121868710