应用程序如何链接静态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)

相关内容

热门资讯

今日重大通报“同城游跑胡子.有... 您好:同城游跑胡子这款游戏可以开挂,确实是有挂的,需要了解加客服微信【4282891】很多玩家在这款...
终于明白“亲友游戏.到底有挂吗... 您好:亲友游戏这款游戏可以开挂,确实是有挂的,需要了解加客服微信【4282891】很多玩家在这款游戏...
“月薪6万,不被裁员”,香港年... 考公的风,还是吹到了香港。2025-2026年度香港特区公务员联合招聘中,最受关注的政务主任(AO)...
最新引进“新天道联盟.到底有挂... 家人们!今天小编来为大家解答新天道联盟透视挂怎么安装这个问题咨询软件客服徽4282891的挂在哪里买...
【第一财经】“微信小程序掼蛋.... 家人们!今天小编来为大家解答微信小程序掼蛋透视挂怎么安装这个问题咨询软件客服徽9784099的挂在哪...
【今日要闻】“新蛮王牛牛.是不... 家人们!今天小编来为大家解答新蛮王牛牛透视挂怎么安装这个问题咨询软件客服徽9784099的挂在哪里买...
移动流量卡真的划算吗?三大运营... 办卡:微 信 公 众 号 搜【 可可 找卡】,每天更新运营商官方高性价比套餐!帮你精准匹配适配流量方...
终于了解“大庆划水麻将.是不是... 有 亲,根据资深记者爆料大庆划水麻将是可以开挂的,确实有挂(咨询软件无需...
【今日要闻】“新蛮王牛牛.真的... 网上科普关于“新蛮王牛牛有没有挂”话题很是火热,小编也是针对新蛮王牛牛作*弊开挂的方法以及开挂对应的...
今日重大消息“乐暴延边麻将.可... 网上科普关于“乐暴延边麻将有没有挂”话题很是火热,小编也是针对乐暴延边麻将作*弊开挂的方法以及开挂对...