应用程序如何链接静态QT Plugin库

  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 <QtPlugin>
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)

转载于:https://blog.51cto.com/lightingmusic/2133410

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值