詳解 Qt 庫中添加插件辦法
Qt 庫中添加插件辦法是本篇文章要講解的內容,前天下載了Qt 4.6.1的最新版本,編譯了一夜終于編譯完成,興沖沖的把以前寫好的程序也用新的版本庫編譯了一遍,但是問題來了。
以前寫的圖像處理的工具居然不支持jpeg格式了,很是奇怪。 搜索了一天得知問題出在這了:以前用的版本是4.3.3,這個版本好像一出來就支持jpeg格式,所以以前沒有注意到這個問題。
現在這個4.6.1不支持了怎么辦?
我們在幫助文檔里可以找到答案:
To link statically against those plugins, you need to use the Q_IMPORT_PLUGIN() macro in your application and you need to add the required plugins to your build using QTPLUGIN. For example, in your main.cpp:
- #include <QApplication>
- #include <QtPlugin>
- Q_IMPORT_PLUGIN(qjpeg)
- Q_IMPORT_PLUGIN(qgif)
- Q_IMPORT_PLUGIN(qkrcodecs)
- int main(int argc, char *argv[]) {
- QApplication app(argc, argv);
- ...
- return app.exec();
- }
- In the .pro file for your application, you need the following entry:
- QTPLUGIN += qjpeg \
- qgif \
- qkrcodecs
但是這樣還是不行,編譯工程的時候會出先
- undefined reference to `qt_plugin_instance_qgif()’
- undefined reference to `qt_plugin_instance_qjpeg()’
等錯誤。
解決方法:在.pro中加入:
- LIBS += C:/Qt/4.3.3/plugins/imageformats/libqgif.a
- LIBS += C:/Qt/4.3.3/plugins/imageformats/libqjpeg.a
如果QT靜態(tài)編譯正確的話,你應該上面這個目錄 下看到這兩個文件libqgif.a和libqjpeg.a (據說以前的QT版本也可能是.lib或.o文件)
對于VS項目呢,可以在項目屬性頁里的 連接器->輸入->添加依賴項里把庫文件添加進去就可以了!
完成!
小結:Qt庫中添加插件的辦法的內容介紹完了,希望本篇文章對你有所幫助!更多內容請參考編輯推薦!