千家信息网

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

发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,错误描述静态编译了QT库后,我的应用程序要链接到这些静态库。但是出现了如图所示错误:运行时错误错误提示:This application failed to start because it coul
千家信息网最后更新 2026年11月01日应用程序如何链接静态QT Plugin库
  1. 错误描述
    静态编译了QT库后,我的应用程序要链接到这些静态库。但是出现了如图所示错误:

    运行时错误错误提示:
    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)

错误 静态 方法 项目 应用程序 程序 链接 应用 位置 全局 关键 关键字 办法 文件 是在 过程 如图 提示 编译 运行 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 南京欣网互联网络科技 科技企业和互联网企业 互联网与科技金融数据 关于新基建和互联网科技 广州互联网科技公司 壹账通互联网科技 奇酷互联网络科技公司 电子科技大学互联网 一五八零互联网科技 互联网巨头投资的硬核科技 科技与互联网哪个更好 互联网科技创新的路径 沐思想互联网科技有限公司 怎样加入科技互联网 江苏苏星互联网科技有限公司 四川互联网展示科技馆设计 宇信科技在杭州互联网排第几 吉林省码上互联网科技电话 互联网领先科技成果宣传视频 中国主要互联网科技公司 互联网是第几次科技革命的成果 互联网科技视频 互联网科技缩写 互联网教育科技公司vipkid 科技互联网的核心竞争力 广州富喜互联网络科技 下一代互联网重大应用科技园 上海同邻互联网科技有限公司规模 互联网科技平台产品运营 10位科技互联网大佬
0