詳解 Qt 庫(kù)中添加插件辦法
Qt 庫(kù)中添加插件辦法是本篇文章要講解的內(nèi)容,前天下載了Qt 4.6.1的最新版本,編譯了一夜終于編譯完成,興沖沖的把以前寫好的程序也用新的版本庫(kù)編譯了一遍,但是問題來了。
以前寫的圖像處理的工具居然不支持jpeg格式了,很是奇怪。 搜索了一天得知問題出在這了:以前用的版本是4.3.3,這個(gè)版本好像一出來就支持jpeg格式,所以以前沒有注意到這個(gè)問題。
現(xiàn)在這個(gè)4.6.1不支持了怎么辦?
我們?cè)趲椭臋n里可以找到答案:
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
但是這樣還是不行,編譯工程的時(shí)候會(huì)出先
- undefined reference to `qt_plugin_instance_qgif()’
- undefined reference to `qt_plugin_instance_qjpeg()’
等錯(cuò)誤。
解決方法:在.pro中加入:
- LIBS += C:/Qt/4.3.3/plugins/imageformats/libqgif.a
- LIBS += C:/Qt/4.3.3/plugins/imageformats/libqjpeg.a
如果QT靜態(tài)編譯正確的話,你應(yīng)該上面這個(gè)目錄 下看到這兩個(gè)文件libqgif.a和libqjpeg.a (據(jù)說以前的QT版本也可能是.lib或.o文件)
對(duì)于VS項(xiàng)目呢,可以在項(xiàng)目屬性頁(yè)里的 連接器->輸入->添加依賴項(xiàng)里把庫(kù)文件添加進(jìn)去就可以了!
完成!
小結(jié):Qt庫(kù)中添加插件的辦法的內(nèi)容介紹完了,希望本篇文章對(duì)你有所幫助!更多內(nèi)容請(qǐng)參考編輯推薦!


















