简体   繁体   English

如何静态和动态地编译Qt插件

[英]How to compile Qt plugins statically and dynamically

I came through terms dynamic and static compiling in Qt. 我在Qt中经历过动态和静态编译的术语。 Could some one explain the difference and how there are done in practice. 有人可以解释一下差异以及在实践中如何做到这一点。

First thing, you need to compile the dynamic plugin as a dll and the static plugin as a static library. 首先,您需要将动态插件编译为dll,将静态插件编译为静态库。

So for the static add something like this to your project file 因此,对于静态添加这样的东西到您的项目文件

CONFIG *= staticlib # 

The dynamic version is just a standard dll, ie 动态版本只是一个标准的dll,即

CONFIG *= dll

Second, specify that you are compiling a plugin: 其次,指定您正在编译插件:

CONFIG *= qt plugin

So what's the difference between those two? 那两者之间有什么区别?

  1. The dynamic plugin is a dll, it will build in the plugins directory which has to be in the application path when running your app. 动态插件是一个dll,它将在运行应用程序时必须位于应用程序路径中的plugins目录中构建。 This can be easily forgotten when deploying the app (and then you might end up with no thumbnails etc. ) 部署应用程序时很容易忘记这一点(然后您可能最终没有缩略图等)。
  2. The static plugin needs to be linked into your application (typically using the QTPLUGIN macro within the profile). 静态插件需要链接到您的应用程序(通常使用配置文件中的QTPLUGIN宏)。 Just linking the static plugin library using the libs *= plugin_name syntax works as well. 只需使用libs * = plugin_name语法链接静态插件库即可。

I prefer 2. because it gives you more control over your build environment and makes the app deployment less buggy... 我更喜欢2.,因为它可以让您更好地控制构建环境,并减少应用程序的部署错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM