Qt5.9 program package release

(Windows platform) How do programs compiled by Qt run on other computers that do not have Qt installed? This article will tell you the answer

Compile the project

Here we take an official routine as the target project, and choose Releasethe way to compile the project.

insert image description here

After the compilation is completed, the program runs automatically (as shown in the figure below), finds the location of the executable file (which can be found in the project build directory),

insert image description here

Copy the executable file separately and put it in an empty folder,

insert image description here

At this point, the file cannot be run. If this is a C or C++ program, it can be run directly, unless you do not add the key Qt library to the environment variable (if you want to run C/ For C++ programs, you need to package those libraries together, which will be introduced later)

insert image description here

run windeployqt

windeployqt is a command tool that comes with Qt. It is located in the bin directory of the Qt compiler. For example, my path is: Qt5.9.0\5.9\mingw53_32\bin

insert image description here

This is a command tool that cannot be run directly. You need to open the console first (enter Win+R, then enter cmd and press Enter), copy the path name of the executable file, and enter cd /d+ executable file path name in the console (right click to paste), enter the package directory,

insert image description here

Then copy windeployqt.exethe absolute path of to the console, followed by the executable file to be packaged,

insert image description here

Press Enter to run, the tool will copy all the dependent libraries of the executable file (except a few Qt core libraries) to the directory where the executable file is located.

insert image description here

At this time, there are many library files and several folders in the package folder (which are also libraries),

insert image description here
At this point, run the executable file under the packaged file again. If the following error occurs, it is very likely that the Qt core library has not been added to the environment variable (of course, it is also feasible to copy the required library directly to the packaged folder, and This is the final step of packaging, see below for details),

insert image description here

insert image description here

After adding the environment variables, the Qt program can run successfully:

insert image description here

Add necessary libraries

The above executable file can be run directly thanks to the windeployqt.extgenerated dependency library and some libraries in global variables, but only wineployqt.exethe generated library is in the packaging folder, so if you want to make the executable file run on other computers that do not have Qt installed To run, we also need to copy a few basic libraries.

These libraries are in the Qt5.9.0\Tools\mingw530_32\bindirectory (here is just the directory on my computer, for reference only), in general, only the following three libraries need to be copied (to be on the safe side, you can also .dllcopy all the files in this directory).

insert image description here

At this point, even if the Qt-related library in the environment variable is removed, the packaged file can still run (it can also run on other computers, provided the system is the same).

insert image description here

a problem encountered

Before, I packaged an executable file compiled on Qt according to the above method, but xxx.exe does not seem to be a Qt executable.an , saying that this is not a Qt executable file, I searched the Internet for a long time and could not find a solution, and finally found that it windeployqt.execannot be used in C/ C++ executable files, or C/C++ executable files only need the above three basic libraries to run on other machines, and no other Qt libraries are needed at all.

insert image description here

Guess you like

Origin blog.csdn.net/weixin_43772810/article/details/123991086
Recommended