QT中的html语言依赖哪个dll,[Qt5] 减少dll依赖和大小(特别是webkit的大小和依赖)

本文介绍了如何在编译Qt5时去除不必要的模块,如openssl, icu等,以及如何裁剪WebKit的大小,以减少依赖和优化dll文件。通过在configure时指定参数,不编译某些模块,例如quick, qml, sensors等,并裁剪webkit自身的大小,可以显著减小dll文件。此外,还提供了调整icu大小的方法,通过定制所需的数据和重新编译ICU库来降低其体积。
摘要由CSDN通过智能技术生成

Qt5的依赖太多, 而且很dll非常大. 折腾了好久, 摸索了一些精简的方法.

webkit是个非常蛋疼的东西, 依赖超多, 又很庞大. 所以需不需要webkit是完全不同的.

如何编译Qt5可以参考本人之前一篇文章 http://www.cnblogs.com/lingdhox/p/3457419.html

一.

1. 在configure时去掉不需要的模块, 比如openssl, icu等.

configure -opensource -developer-build -mp -platform win32-msvc2010 -nomake examples -nomake tests -no-icu -no-openssl -no-iconv -no-qml-debug -no-plugin-manifests

更多参数可以configure -help 查看

-no-plugin-manifests 去掉插件dll的manifests文件

需要注意:  如果要使用webkit, 那么icu是必须的.

2. 在configure时, 指定qconfig文件

该方法在嵌入式中使用较多, Qt支持feature裁剪.

在qtbase\src\corelib\global\下有一些qconfig-xxx.h的文件, 就是指定了不同的feature.

Qt tools下有个工程qttools\src\qtconfig , 编译这个项目, 运行后, 是一个图形化的裁剪feature工具. 它打开qtbase\src\corelib\global\下的qfeatures.txt,  然后你可以自由选择需要的feature, 保存成qconfig-myconfig.h

然后在运行configure时. 添加 -qconfig myconfig

我试过这个方法, 但结果是有些地方引用头文件出错. 而且没有用到feature很少, 就不深入研究了.

3. 去掉webkit的quick qml printsupport sensors Qt5V8依赖, 并裁剪webkit本身的大小

打开qtwebkit\Tools\qmake\mkspecs\features下的configure.prf  、features.prf和features.pri

features.prf中注释这四行(加#)

#haveQtModule(quick): WEBKIT_CONFIG += have_qtquick

#else: CONFIGURE_WARNINGS += "QtQuick module not found, QML APIs will not be built"

#haveQtModule(printsupport): WEBKIT_CONFIG += have_qtprintsupport    #haveQtModule(sensors): WEBKIT_CONFIG += orientation_events device_orientation

这样编译出来的webkit.dll不依赖quick qml printsupport sensors

features.prf中这几行config

config_libxml2: WEBKIT_CONFIG += use_libxml2

config_libxslt: WEBKIT_CONFIG += xslt

config_libzlib: WEBKIT_CONFIG += use_zlib

config_libwebp: WEBKIT_CONFIG += use_webp

的定义在qtCompileTest中

qtbase\mkspecs\features\configure.prf下的解释

# Try to build the test project in $$QMAKE_CONFIG_TESTS_DIR/$$1

# ($$_PRO_FILE_PWD_/config.tests/$$1 by default).

#

# If the test passes, config_$$1 will be added to CONFIG.

# The result is automatically cached. Use of cached results

# can be suppressed by passing CONFIG+=recheck to qmake.

#

# Returns: true iff the test passes

defineTest(qtCompileTest) {

positive = config_$$1

done = done_config_$$1

done_config_$$1会输出到.qmake.cache

比如qtimageformats\qtimageformats.pro 中添加libwebp

requires(qtHaveModule(gui))

load(configure)

qtCompileTest(jasper)

qtCompileTest(libmng)

qtCompileTest(libtiff)

qtCompileTest(libwebp)

load(qt_parts)

configure.prf 中把

WEBKIT_CONFIG += \

build_webkit1 \

build_webkit2 \

build_tests \

$$WEBKIT_TOOLS_CONFIG

改成

WEBKIT_CONFIG += \

build_webkit1 \

build_tests \

$$WEBKIT_TOOLS_CONFIG

不编译webkit2 , webkit2依赖Qt5V8,  提升HTML5 , js, qml 的支持. 并提升性能.

需不需要就看情况了

features.pri 中一堆宏, 用于控制特性. 需要自己检查那些特性不需要.

注意: 这三个文件的修改要在编译前.

qtwebkit\makefile是在.\makefile中编译module-qtwebkit时动态生成的(不存在才会生成)

所以如果修改三个文件后, 想重新编译, 需要删除webkit下新生成的所有makefile

makefile

source\Makefile.api

source\Makefile.api.Debug

source\Makefile.api.Release

source\Makefile.widgetsapi

source\Makefile.widgetsapi.Debug

source\Makefile.widgetsapi.Release

source\Makefile.QtWebKit

source\JavaScriptCore\Makefile.jsc

source\JavaScriptCore\Makefile.jsc.Debug

source\JavaScriptCore\Makefile.jsc.Release

source\JavaScriptCore\Makefile.LLIntOffsetsExtractor

source\JavaScriptCore\Makefile.LLIntOffsetsExtractor.Debug

source\JavaScriptCore\Makefile.LLIntOffsetsExtractor.Release

source\JavaScriptCore\Makefile.JavaScriptCore.DerivedSources

source\JavaScriptCore\Makefile.JavaScriptCore

Makefile.JavaScriptCore.Target

Makefile.JavaScriptCore.Target.Debug

Makefile.JavaScriptCore.Target.Release

Source\WebCore\Makefile.WebCore.DerivedSources

Source\WebCore\Makefile.WebCore.Target

Source\WebCore\Makefile.WebCore.Target.Debug

Source\WebCore\Makefile.WebCore.Target.Release

Source\WebCore\Makefile.WebCore

Source\WebKit\Makefile.WebKit1

Source\WebKit\Makefile.WebKit1.Debug

Source\WebKit\Makefile.WebKit1.Release

Source\WebKit2\Makefile.WebKit2.DerivedSources

Source\WebKit2\Makefile.WebProcess

Source\WebKit2\Makefile.WebProcess.Debug

Source\WebKit2\Makefile.WebProcess.Release

Source\WebKit2\Makefile.WebKit2.Target

Source\WebKit2\Makefile.WebKit2.Target.Debug

Source\WebKit2\Makefile.WebKit2.Target.Release

Source\WebKit2\Makefile.WebKit2

source\wtf\Makefile.WTF

source\wtf\Makefile.WTF.Debug

source\wtf\Makefile.WTF.Release

Source\ThirdParty\ANGLE\Makefile.ANGLE.Target

Source\ThirdParty\ANGLE\Makefile.ANGLE.Target.Debug

Source\ThirdParty\ANGLE\Makefile.ANGLE.Target.Release

Source\ThirdParty\ANGLE\Makefile.ANGLE

Source\ThirdParty\ANGLE\Makefile.ANGLE.DerivedSources

Source\WebKit\qt\declarative\Makefile.declarative.public

Source\WebKit\qt\declarative\Makefile.declarative.public.Debug

Source\WebKit\qt\declarative\Makefile.declarative.public.Release

Source\WebKit\qt\declarative\Makefile.declarative

Source\WebKit\qt\declarative\experimental\Makefile.declarative.experimental

Source\WebKit\qt\declarative\experimental\Makefile.declarative.experimental.Debug

Source\WebKit\qt\declarative\experimental\Makefile.declarative.experimental.Release

需要删除这些, 所以我觉得从压缩包里重新拷贝一份qtwebkit的源码出来编译, 更方便.  环境也更干净

运行 nmake module-qtwebkit 然后会生成一个.qmake.cache

打开可以看到WEBKIT_CONFIG (即刚才修改的选项)

4. 裁剪icu的大小, icudt*.dll, icuin*.dll, icuuc*.dll

http://userguide.icu-project.org/icufaq

How can I reduce the size of the ICU data library?

1). 根据官方faq的方法, 定制自己需要的数据

http://apps.icu-project.org/datacustom/

先在get data library下选择版本, 比如ICU 51 Data

然后选择自己的需要的语言版本. 这样最后的icudt51l.dat 大概在几M左右.

2). 下载对应版本的源码包.

替换icu\source\data\in 下的icudt*l.dat

打开icu\source\allinone的VS工程

编译.  最终生成的文件icu\ 下

5. 最终生成的dll:

Qt5WebKit.dll 10M

icudt51.dll  3M

icuin51.dll   1.3M

icuuc51.dll  1M

来源:https://www.cnblogs.com/lingdhox/p/3685360.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值