把静态编译的QT添加到QTCreator当中创建新工程

How to integrate static version of Qt additionally to QtCreator

Open QtCreator and go to the Tools / Options menu. Select Qt4:

Select Options - Qt4 - Add

Add a new version by pressing the plus button enter a name and the path to qmake (Path-To-Qt-SDK\qt_static\bin\qmake.exe) add the MinGW directory (copy from 4.7.0)

Changes in the settings

If you create a new project, you are asked, which Qt version you want to use. Leave both checkboxes checked. Create new project

If you already have a project and want to add this version, go to Projects (left hand of QtCreator) and add a setting.

Change project settings

For the static project configuration, you should add CONFIG+=static in the command line. Open the project settings, and press details for the qmake step. In the additional arguments, add CONFIG+=static

changes qmake step

In the project (*.pro) file, add the following:

static { # everything below takes effect with CONFIG ''= static
 CONFIG+= static
 CONFIG += staticlib # this is needed if you create a static library, not a static executable
 DEFINES+= STATIC
 message("~~~ static build ~~~") # this is for information, that the static build is done
 mac: TARGET = $$join(TARGET,,,_static) #this adds an _static in the end, so you can seperate static build
from non static build
 win32: TARGET = $$join(TARGET,,,s) #this adds an s in the end, so you can seperate static build from
non static build
}

What also makes sense is to add a d to the binary, if you create a debug build:

# change the nama of the binary, if it is build in debug mode
CONFIG (debug, debug|release) {
 mac: TARGET = $$join(TARGET,,,_debug)
 win32: TARGET = $$join(TARGET,,,d)
}

Now you have it. Build the static version (select he static project settings and build it).

changes qmake step

猜你喜欢

转载自blog.csdn.net/yuexiaxiaoxi27172319/article/details/51987004