Summary of QT program deployment in Windows

Source: Internet
Author: User
Table of contents
  • Reference description:
  • There are two ways to deploy and release the QT Program
  • I. Static Compilation
    • 1. Compile QT.
    • 2. Compile the program.
    • 3 add plug-ins
    • 4 Add libs
    • 5. Solve the mingwm10.dll dependency problem of mingw.
  • Ii. dynamic compilation
Reference description:

Link: http://hi.baidu.com/jzinfo/blog/item/c17c3f6d4ff439fe431694c3.html

The following describes some of the content collected on the Internet and the content in the QT help (deploying an application on QT/Windows)

There are two ways 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. Compile QT statically.

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.

If vc2005platform is used, the configure.exe-static-platform win32-msvc2005 completes static Compilation When compiling qt2.

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> // 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+0×1c9):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

In. add libs + = C:/QT/4.3.3/plugins/imageformats/libqgif to pro. A libs + = C:/QT/4.3.3/plugins/imageformats/libqjpeg. a. If the QT static compilation is correct, you should see the libqgif files in the preceding directory. A And libqjpeg. A (it is said that the previous QT version may also be. lib or. o file)

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:

Generally, 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 and running the program in 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, the image file may not be displayed. Solution: Create an imageformats directory in the program folder (this name must be used ), copy the DLL files under the plugin/imageformats directory under the QT directory. This completes the dynamic connection.

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.

Author: Le Cao

Date: 2010-10-12 18:02:28 CST

HTML generated by org-mode tag = 7.01g in Emacs 23

Related Article

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.