QT静态库使用插件的小TIP

来源:互联网 发布:linux eclipse -inst 编辑:程序博客网 时间:2024/05/22 23:39

本来想在QT下使用ODBC的plugin,但是发现编译生成的qsqlodbc.lib无法在plugin文件夹中载入,网上google了下,找到了答案,需要在源文件中加入如下声明:

 

//目的是引入接口,以便将插件的代码编译进去

#include <QtPlugin> 
Q_IMPORT_PLUGIN(qsqlodbc)

 

查了下Qt Assistant,发现QtPlugin是一个定义宏的头文件,之下的Q_IMPORT_PLUGIN宏就是在这个文件里定义的。

Q_IMPORT_PLUGIN在QA里是这么解释的:This macro imports the plugin named PluginName, corresponding to theTARGET specified in the plugin's project file. Inserting this macro into your application's source code will allow you to make use of a static plugin.

果然,这个宏的作用是引入static plugin。

 

值得一提的是,动态的dll plugin是不需要这么做的,原因是QT application可以动态的载入DLL文件,而LIB则不行,这跟QT关系倒是不大,主要一个是compile-time load而另一个是run-time load,大抵是这样的,希望我不要理解错。

0 0
原创粉丝点击