PDA

View Full Version : What is the point of plugins?



msimurin
31st July 2010, 02:35
I am aware that you can extend qt features and application with plugins but what is the deal with all complications(macros, plugin commands, plugin loading etc) couldnt you just make a simple class and extend your app like that?

Lykurg
31st July 2010, 06:04
The big point is that you can extend your application without rebuilding it. Even if you alter your plugin, you don't have to recompile your app. (That's important if your app is huge and needs lot of time for compiling.) Further you can load your only the needed plugins at runtime. Thus the resources for your application are lower compared to a "full including" application.

Another thing is, that others can develop plugins for your application and use it. You don't have to give them your sources.

tbscope
31st July 2010, 06:19
I am aware that you can extend qt features and application with plugins but what is the deal with all complications(macros, plugin commands, plugin loading etc) couldnt you just make a simple class and extend your app like that?

There are a few obvious reasons why you can't just do that.

Plugins use the Factory design pattern. This means you create an abstract base class and then create implementation classes based on that base class. The plugin loader acts as the factory. You can have a function called bool hasCapabilities(...) in your abstract class and the factory can use it to determine which plugin should be used.

Loading of the plugins is also straightforward. You can't expect your program to find and open plugins on its own. How would it do that? Instead, you place the plugins in a special folder, known either by the system or your program. Then you look into this folder and use the factory (plugin loader) to open (create) those plugins.

Then there are the macros. Since you're dealing with separate libraries you need to tell if you are importing symbols into your library or exporting them to another program or plugin. This is important, because if you don't tell if you're importing or exporting, the program will not find the implementation of your abstract base class in the plugin.

SixDegrees
31st July 2010, 11:46
Also, the macros and the rest of the Qt plugin framework ensures cross-platform compatibility. Once your code works on one machine, it can be recompiled and run on a completely different platform without any changes. If you've tried writing dynamic libraries using the "raw" approach, you'll know how many differences arise between, say, Linux and Windows.

And at the end of the day, using native libraries and function calls is considerably more complex than using Qt's handful of macros.