Qt 6, a commonly used GUI library that supports Chinese in C++: Release of the project

C++ commonly used GUI library Qt 6 that supports Chinese : the release of the project

This article follows the introduction of the previous article "Qt 6, a commonly used GUI library that supports Chinese in C++: project structure and use of resource files" https://blog.csdn.net/cnds123/article/details/130741807 , and use it example of.

If the program code can be compiled and run correctly, the release of the project can be considered.

Distributing Qt programs requires consideration of various factors. You need to know the requirements of the target platform, know how to compile and package the program, and be able to manage its dependencies and release versions.

Qt Creator classifies and stores project source files and compiled files. Beginners often can't find where the generated executable file .exe is.

In Qt Creator, the generated executable file (.exe file) will be placed in the project's build directory by default. The location of the build directory can be configured in Qt Creator's project settings.

Build and run ( Build & Run ) directory

Qt Creator classifies and stores project source files and compiled files. The build directory is used to store the files generated during the compilation process of this project, such as database files, executable files, etc.

View or modify the build directory

View or modify the build directory of the project in Qt Creator, see the figure below, and follow the steps below:

Open Qt Creator and load your project.

In the left panel, select the Projects icon (usually displayed as a wrench icon).

In the "Project" tab, view or modify the build directory according to the actual situation .

After saving the changes, the next time you build, the project will be compiled with the new build directory.

Note: Modifying the build directory will affect the storage location of the previous build products. It may be necessary to rebuild the project to ensure that the previous build products are updated. In some cases, it may be necessary to perform a clean operation (click "Build" > "Clean Project" on the top menu bar) to prevent problems caused by old build files.

build mode (build version)

Qt provides three different build modes (build versions): Debug, Profile and Release. These modes involve different compilation options and optimization settings to meet the needs of different stages in the development process.

Debug (debug) mode:

Debug mode is mainly used for developing and debugging applications. It uses additional information, such as debug symbols, to make it easier for developers to locate and resolve code issues. In Debug mode, the compiler typically does not perform any optimizations to ensure that the code behaves as expected. Executables generated under this configuration are larger and run slower. The project in Debug mode can be combined with the debugger to perform breakpoint debugging, memory analysis and other operations at runtime.

Profile (performance analysis) mode:

Profile mode is similar to Debug mode, but includes additional performance analysis tools (such as performance counters and tracers). These tools allow developers to examine application performance bottlenecks and resource consumption. In Profile mode, the compiler may perform certain optimizations in order to be closer to the actual operating environment. However, this mode still includes debugging information, so the executable file size is still larger. Profile mode is suitable for scenarios that require performance analysis and adjustment of code.

Release (release) mode:

Release mode is used to prepare the final version of the application. In Release mode, the compiler will perform various optimization operations to improve the execution speed of the application and reduce the file size. Executables in this mode do not contain debugging information, so they are smaller and run faster. However, locating the problem using a debugger becomes difficult due to the lack of debug information. Release mode is typically used to produce a version of an application that can be distributed to users.

In Qt Creator, you can select the required build mode from the build mode drop-down menu (usually located in the lower left corner). After selecting the appropriate mode, click the "Build" icon to compile. Please note that when switching build modes, make sure that the corresponding build directory is set correctly.

Compile the application you want to release in release mode, and then generate an executable file.

Compile in Release mode

Note that when compiling your application in Release mode, make sure you have properly set up your project and resolved all compilation warnings and errors.

To compile in Release mode in Qt Creator, please follow the steps below:

Open Qt Creator and load your project.

In the lower left corner, find the build mode switcher. It usually appears as a drop-down menu that toggles between Debug, Profile, and Release modes.

Select the "Release" mode from the drop-down menu. At this point, Qt Creator will compile the project using the Release mode setting.

To start compiling, click the hammer icon next to the green play icon on the top toolbar (or press the shortcut Ctrl+B or Cmd+B, or choose Build > Build Project from the top menu bar).

Qt Creator will use Release mode for compilation. After compilation, you can find the resulting executable in the "release" subfolder of the build directory.

Find the generated executable file in the "release" subfolder under the build directory, here is ch01.exe. At this point, it can't be used yet. Double-clicking it will report an error, see below.

project release

How to let others use ch01.exe above? Don't be too happy, just read on.

Projects created with QT Creator can be started and run in QT Creator, but double-clicking the ch01.exe file in the "release" subfolder prompts a system error:

what to do? Look down, manually create a folder such as MyQt, and put the bin folder and plugins file in the 6.2.4\mingw_64 (where 6.2.4 is the Qt version number, depending on your actual situation) folder under the Qt installation directory folder to the MyQt folder, and then copy ch01.exe to the bin folder of the MyQt folder, and then the MyQt folder can be used by others. Among them, ch01.exe can be renamed. Send this folder to a computer that has not installed Qt, and it can also be opened. However, such a release contains more useless files and is not very professional. In this way, the entire folder is about 200 M (although the ch01.exe in it is very small).

The following introduces the use of Qt's windeployqt tool to release

windeployqt.exe is a Windows platform release tool that comes with Qt. It is used to create an application release package. It can automatically copy various library files and plug-ins required for an application to run. Official introduction to Qt for Windows - Deployment | Qt 6.5

Open the Qt command line terminal interface in the "Start" menu, see the figure below:

[Input in the Qt command line terminal

windeployqt.exe -h

Enter, you can view the command help

Create a new folder where you think is appropriate, copy the .exe file under the "release" folder to the newly created folder, here I create a folder MyQtTest on the D: drive, and copy ch01.exe to the file folder

Enter on the command line

windeployqt application full path

I am here

windeployqt  D:\MyQtTest

Press Enter to execute the release command, see the figure below:

 Tip: If the application path contains spaces, you need to wrap the entire path string in double quotes.

After the wait is complete, enter the application directory and you can see that many dependent libraries and data files have been added to the directory. See the picture below:

Click on your .exe in this directory to run it directly:

Send this folder to a computer that has not installed Qt to see if it can be opened. If there is no problem, you can publish it like this. In this way, the entire folder is about 50 M (although the ch01.exe in it is very small).

Going a step further, you can make an installation file. There are a lot of software for making installation files, such as Inno Setup, which is a free Windows installer making software, and you can also use the official Qt Installer Framework tool Qt Installer Framework to make installation packages. The Qt Installer Framework provided by Qt is a set of tools and utilities for creating one-time installers.

Official download: https://download.qt.io/official_releases/qt-installer-framework/

Official documentation: https://doc.qt.io/qtinstallerframework/index.html

For these, there is not much to say here.

Finally, again, Qt 6 and later versions no longer support Windows 7.

appendix

Qt 6.2.1 Official documentation (Chinese human translation) http://qt6.digitser.top/
A brief description of Qt Creator tutorial https://www.zhangshengrong.com/p/Ap1Zey3AX0/
Release of Qt applications (windeployqt ) https://blog.51cto.com/u_15346415/5172452

Guess you like

Origin blog.csdn.net/cnds123/article/details/130827966