应用程序如何链接静态QT Plugin库
admin
2023-01-31 00:21:50
0
  1. 错误描述
    静态编译了QT库后,我的应用程序要链接到这些静态库。但是出现了如图所示错误:
    应用程序如何链接静态QT Plugin库
    运行时错误错误提示:
    This application failed to start because it could not find or load the Qt platform plugin "windows" in "".

  2. 解决过程
    Google关键字“Qt staticPlugins”, to get the first result as:

How to Create Qt Plugins

To link plugins statically, you need to add the required plugins to your build using QTPLUGIN.

In the .pro file for your application, you need the following entry:

QTPLUGIN += qjpeg \
qgif \
qkrcodecs
qmake automatically adds the plugins to QTPLUGIN that are typically needed by the Qt modules used (see QT), while more specialized plugins need to be added manually. The default list of automatically added plugins can be overridden per type. For example, to link the minimal plugin instead of the default Qt platform adaptation plugin, use:

QTPLUGIN.platforms = qminimal
If you want neither the default, nor the minimal QPA plugin to be linked automatically, use:

QTPLUGIN.platforms = -
The defaults are tuned towards an optimal out-of-the-box experience, but may unnecessarily bloat the application. It is recommended to inspect the linker command line built by qmake and eliminate unnecessary plugins.

Details of Linking Static Plugins
To cause static plugins actually being linked and instantiated, Q_IMPORT_PLUGIN() macros are also needed in application code, but those are automatically generated by qmake and added to your application project.

If you do not want all plugins added to QTPLUGIN to be automatically linked, remove import_plugins from the CONFIG variable:

CONFIG -= import_plugins
Creating Static Plugins
It is also possible to create your own static plugins, by following these steps:

Add CONFIG += static to your plugin's .pro file.
Use the Q_IMPORT_PLUGIN() macro in your application.
Use the Q_INIT_RESOURCE() macro in your application if the plugin ships qrc files.
Link your application with your plugin library using LIBS in the .pro file.
See the Plug & Paint example and the associated Basic Tools plugin for details on how to do this.

Note: If you are not using qmake to build your plugin you need to make sure that the QT_STATICPLUGIN preprocessor macro is defined.

3. 解决方法
上述方法均可以使用。我的项目是VC项目,最直接的办法是在main 文件中全局位置调用宏

// link to static QT lib, following lines to import platform static lib's header
#include
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)

相关内容

热门资讯

济南一广场突现“知了大军”密密... 近日,有济南市民在社交媒体发布视频称:在当地彩石附近的一处广场地面上密密麻麻聚集了很多类似知了的昆虫...
伊朗军队:打击科威特境内多处美... 当地时间23日,伊朗军队在一份公告中指出,几小时前,伊朗军队对科威特多哈营地的美军弹药和后勤仓库、阿...
洛阳“珠宝大王”年永安沉浮:涉... 澎湃新闻记者 王鑫 实习生 林晨 林宜之河南洛阳的“珠宝大王”年永安淡出公众视野多年后,这个曾把“金...
聚焦核心AI项目,亚马逊裁撤其... 亚马逊在本周三宣布新动态,公司正在裁撤通用人工智能(AGI)部门的部分员工,这标志着亚马逊在持续向人...
上海交大发布第七届“十大科技进... 7月22日,上海交通大学第七届“十大科技进展”在闵行大零号湾成果转化中心发布。本届入选成果包括6项基...
MEMS微纳加工进入共享时代:... 一、行业背景:科研与中试的"产线困境" 一、行业背景:科研与中试的"产线困境" 在半导体与微纳制造领...
行业首款水冷+185Hz超高刷... 一、前言:9英寸机身里塞下了整个Steam库 拿到红魔游戏平板5 Pro之前,我对它没太大期待,正常...
雷军亲自下场讲物理!小米澎程不... 7月22日,小米CEO雷军在微博抛出“灵魂三问”,9系全尺寸大空间四驱SUV你选哪个? 1. 大电池...
最新民调:特朗普的支持者对伊朗... 美伊谅解备忘录失效,停火局面被打破,双方最近大打出手。据美媒报道,美国最新民调显示,特朗普的支持者对...
专业可靠的AirTag平替销售... 智能防丢市场新选择:AirTag平替产品的核心选购逻辑与可靠源头厂商解析 在苹果AirTag带动下...