Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How applications link static QT Plugin libraries

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Error description

After compiling the QT libraries statically, my application links to these static libraries. But there is an error as shown in the figure:

Runtime error error prompt:

This application failed to start because it could not find or load the Qt platform plugin "windows" in ".

Solution process

Google keyword "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. Solution method

All the above methods can be used. My project is a VC project, and the most direct way is to call macros in the global location in the main file.

/ / link to static QT lib, following lines to import platform static lib's header

# include

Q_IMPORT_PLUGIN (QWindowsIntegrationPlugin)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report