QT program is deployed under Windows release

Source: Internet
Author: User
Tags file copy

Reprint: http://www.cnblogs.com/Fan_Fan/archive/2010/05/29/1746860.html

QT program is deployed under Windows release

The following includes some of the content collected online, as well as the Qt help (deploying an application on Qt/windows)

First, open the Windows console, and then locate the VS installation directory in the bin to execute the Vcvars32.bat script. After execution, all of the environment variables required by VS are already set.

My environment is QT 4.3.3 + mingw32-make

There are two ways to deploy the release QT program:

The first, statically compiled, generates a single executable file.

Second, dynamic compilation, you need to attach the required DLL files.

The first static compilation

1 compiling QT.

To compile statically, the first requirement is that QT be statically compiled. Execute in QT directory:

Configure.exe-static-release

Make SUB-SRC

You can compile a static library. If you are just distributing the program, you can mingw32-make release sub-src to compile only one static library.

This process takes 1-2 hours. The QT directory will become around 1.8G. Note: Mingw32-make and make are the same.

If using the VC2005 platform, when compiling QT, Configure.exe-static-platform win32-msvc2005

Then NMAKE SUB-SRC or NMAKE release SUB-SRC completes the static compilation.

2 Compile the program.

Then go to your own program directory to perform the following:

Make clean

Qmake-config Release

Make

This will get a very large executable program, but there will also be an important problem, that is, the picture file does not appear.

According to QT help, Qt Jpeg,gif and other images are supported in the form of plugins, and now we do not include any plugins.

In the main.cpp:

#include

#include//This

Q_import_plugin (QJPEG)//This

Q_import_plugin (qgif)//This

int main (int argc, char *argv[])

{

Qapplication app (argc, argv);

...

return App.exec ();

}

Add in. Pro:

Qtplugin + = Qjpeg qgif

CONFIG + = static

QT Help is done here, but I compile the program with an error as follows:

RELEASE/MAIN.O (. text+0x1c9): main.cpp:

Undefined reference to ' qt_plugin_instance_qgif () '

Undefined reference to ' qt_plugin_instance_qjpeg () '

4 Join Libs

Join in. Pro:

LIBS + = C:/QT/4.3.3/PLUGINS/IMAGEFORMATS/LIBQGIF.A

LIBS + = C:/qt/4.3.3/plugins/imageformats/libqjpeg.a

If QT statically compiles correctly, you should see these two files in the above directory LIBQGIF.A and LIBQJPEG.A (it is said that the previous QT version may also be a. lib or. o file)

5 Solving the Mingwm10.dll dependency problem of MinGW

Lflags =-enable-stdcall-fixup-wl,-enable-auto-import-wl,-enable-runtime-pseudo-reloc-static-wl,-s-wl-mthreads- Wl,-subsystem,windows

Quote

Generally only used when the threads to use the Mingwm10.dll, we usually encounter the "lack of mingwm10.dll" problem, you can delete the "makefile.release" parameter after the program Qmake generate-mthreads file, generally in Behind "Lflags". Of course, this is only a temporary solution, each time you have to manually modify, you can compile QT before you modify qmake.h, but this method is not recommended. In fact, Mingwm10.dll is more than 10 k, each time the program is released together packaging also does not matter.

At this point the compilation also get a very large executable program (I wrote this snake altogether more than 500 lines, generated EXE has 8M). Compress it with Asppack. Can be sent to the user (this is 2.6M).

Quote: "This compiled program is relatively large, you can first use the strip command to remove some useless information in the program, with Aspack or UPX compression shell software compression, the compression rate of the two basically reached more than 30%, the compression effect is very obvious. ”

The second type: Dynamic compilation is easy.

With QT default installation, put the generated release EXE file, and the following several core files in a folder:

MINGWM10. Dll

QTGUI4. Dll

QTCORE4. Dll

VC2005 several DLL files required by the compiler to run the program

Microsoft.VC80.CRT.manifest in X:\Program Files\Microsoft Visual Studio 8\vc\redist\x86\\microsoft.vc80.crt

Msvcm80.dll

Msvcp80.dll

Msvcr80.dll

QtCore4.dll

QtGui4.dll

So you can run it. But the picture file still may not show up, the solution:

Put the program folder, create a imageformats directory (must be the name), the QT directory under the Plugin/imageformats directory of the corresponding DLL file copy the past. This makes the dynamic connection complete.

Issues to note when releasing the QT program in Chinese:

After using QT to write the program and write the Chinese language file (. qm file), published to a system that has not been installed QT, but found that only the fixed interface text in the Chinese can display normally, and the program runs in the process of saving to such as TXT, XML file in Chinese has become a strange code, And read back will become "?".

The workaround is simple and there are several ways to do it:

1) Install the above Chinese code library file in the executable program directory under the codecs directory, when the program starts, the initialization process in Qtcore will automatically find the directory and load into memory.

2) when the QT program starts, use the code to specify the QT library search path.

3) Write the Qt.config file, place it in the executable directory, and define the path to the codecs.

4) for Qt compiled with static, write this macro command in the main program file: Q_import_plugin (Qcncodecs), and add the corresponding LIB file in link.

I don't have much to say, read the QT documentation: doc/html/plugins-howto.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.