How to build Qt5 app with their static libs?

2019-06-12 13:59发布

问题:

I'm a Qt beginner and I want to know how to build Qt5 apps with their static libraries. Is that possible to build with static libs everything that can be build with dll's ?. I want to know because I don't want to install Qt libs everywhere where I want my apps to be running. For example I want to build with static libs app which code is in this post:

Widgets must be created in the GUI thread Error !. How to correct the code?

Is that possible ? How to do that ?

回答1:

In order to use Qt as a static library, you have to rebuild Qt itself. You can find a guide here

It recommends rebuilding Qt as following:

cd C:\path\to\Qt
configure -static <any other options you need>
nmake sub-src

Make sure you've embedded all plugins you need. (see configure options)

However, not all Qt parts can be built as a static libraries. As far as I know, you may expose some difficulties with Webkit.

After rebuilding Qt, you can build your apps, as usual.

Note also, that Qt is licensed under LGPL or GPL or commercial licence. Using static version of Qt can impose some limitations on your app distributions.