應用程序如何鏈接靜態(tài)QTPlugin庫-創(chuàng)新互聯

  1. 錯誤描述
    靜態(tài)編譯了QT庫后,我的應用程序要鏈接到這些靜態(tài)庫。但是出現了如圖所示錯誤:
    應用程序如何鏈接靜態(tài)QT Plugin庫
    運行時錯誤錯誤提示:
    This application failed to start because it could not find or load the Qt platform plugin "windows" in "".

    專注于為中小企業(yè)提供成都網站制作、網站設計服務,電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)湖濱免費做網站提供優(yōu)質的服務。我們立足成都,凝聚了一批互聯網行業(yè)人才,有力地推動了上千多家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網站建設實現規(guī)模擴充和轉變。
  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)

另外有需要云服務器可以了解下創(chuàng)新互聯cdcxhl.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

分享標題:應用程序如何鏈接靜態(tài)QTPlugin庫-創(chuàng)新互聯
URL標題:http://muchs.cn/article34/sppse.html

成都網站建設公司_創(chuàng)新互聯,為您提供小程序開發(fā)軟件開發(fā)、企業(yè)建站、定制網站品牌網站設計、關鍵詞優(yōu)化

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯

網站托管運營