Summary of deploying and releasing the QT program in windows

Source: Internet
Author: User
The following describes some of the content collected on the Internet and the content in the qt help (Deploying an Application on Qt/Windows)
My environment is QT 4.3.3 + mingw32-make
There are two methods to deploy and release the QT program:
First, static compilation can generate a single executable file.
The second method is dynamic compilation, and the required dll file must be attached at the same time.
I. Static Compilation
1. Compile QT.
To perform static compilation, QT must be statically compiled. Run the following command in the QT directory:
Configure.exe-static-release
Make sub-src
You can compile the static library. If it's just for distribution, you can also mingw32-make release sub-src to compile only one static library.
This process takes 1-2 hours. The QT directory will change to around 1.8G. Note: The mingw32-make and make are the same.
Configure.exe-static-platform win32-msvc2005
Then nmake sub-src or nmake release sub-src completes static compilation.
2. Compile the program.
Then run the following command in your own program directory:
Make clean
Qmake-config release
Make
In this case, a very large executable program will be generated, but an important problem is that the image file cannot be displayed.
According to the help of QT, jpeg, gif, and other images in QT all exist in the form of plug-ins. Currently, we have not included any plug-ins.
3 add plug-ins
In main. cpp:
# Include <QApplication>
# Include <QtPlugin> // This
Q_IMPORT_PLUGIN (qjpeg) // This
Q_IMPORT_PLUGIN (qgif) // This
Int main (int argc, char * argv [])
{
QApplication app (argc, argv );
...
Return app.exe c ();
}
Add:
QTPLUGIN + = qjpeg qgif
CONFIG + = static
In the help of QT, the following error occurs when I compile the program:
Release/main. o (. text + 0x1c9): main. cpp:
Undefined reference to 'qt _ plugin_instance_qgif ()'
Undefined reference to 'qt _ plugin_instance_qjpeg ()'
After a long time of research, we found a solution to the problem:
4 Add LIBS
Add:
LIBS + = C:/Qt/4.3.3/plugins/imageformats/libqgif.
LIBS + = C:/Qt/4.3.3/plugins/imageformats/libqjpeg.
If the QT static compilation is correct, you should see the libqgif. a and libqjpeg. a files in the above directory (it is said that the previous QT versions may also be. lib or. o files)
At this time, you can compile and run properly. However, mingwm10.dll is required for running.
5. Solve the mingwm10.dll dependency problem of MinGW.
In Makefile. release, find:
LFLAGS =-enable-stdcall-fixup-Wl,-enable-auto-import-Wl,-enable-runtime-pseudo-reloc-static-Wl, -s-Wl-mthreads-Wl,-subsystem, windows
Delete "-mthreads"
Quote:
Mingwm10.dll is used only when threads is used. We usually encounter the "lack of mingwm10.dll" problem. You can generate makefile in the qmake program. delete the "-mthreads" parameter after the release file, usually after "LFLAGS. Of course, this is only a temporary solution. You must manually modify it each time. You can also modify qmake. h before compiling QT. However, this method is not recommended. In fact, mingwm10.dll is more than 10 K, and it does not matter if it is packaged together when each program is released.
For more information, see:
Http://lists.trolltech.com/qt-interest/2006-08/thread00942-0.html
Http://lists.trolltech.com/qt-interest/2005-10/thread00381-0.html#msg00553
At this time, the compilation will also get a very large executable program (I wrote more than 500 lines in total, and the generated exe is 8 Mb ). Use AspPack to compress the data. You can send it to the user (2.6 MB at this time ).
Quote: "The program compiled in this way is relatively large. You can use the strip command to Remove useless information in the program and compress it with ASPack, UPX, and other compression and shelling software, both of them have a compression ratio of more than 30%, and the compression effect is quite obvious. "

Ii. dynamic compilation
Dynamic compilation is easy. Use QT's default installation to put the exe files under the generated release and the following core files in a folder:
MINGWM10.DLL
QTGUI4.DLL
QTCORE4.DLL
Several dll files required for compiling the program running VC2005
Microsoft. VC80.CRT. manifest is located in x:/Program Files/Microsoft Visual Studio 8/VC/redist/x86/Microsoft. VC80.CRT
Msvcm80.dll
Msvcp80.dll
Msvcr80.dll
QtCore4.dll
QtGui4.dll
In this way, you can run. However, image files may not be displayed. solution:
Create an imageformats directory (which must be the name) in the program folder, and copy the corresponding dll files under the plugin/imageformats directory under the qt directory. This completes the dynamic connection.
Or you can create a qt. conf file in the folder of your application to write:
[Paths]
Prefix = C:/Qt/4.4.0

Create plugins/imageformats/q1_4.dll under C:/Qt/4.4.0. You can set this Prefix by yourself. Note: You can use Microsoft's Dependency Walker tooltool to compile a depends.exe program to view which dll files are associated with an exe file.
Note: You need to test whether the released program has DLL dependencies on a system without QT installed.

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.