PDA

View Full Version : Plugins support Help!



Chaid
4th July 2006, 09:26
Hello!

I'm writing a book collection manager now (qt4) and want to know how to do the plugins support for different file formats.

Docs from Qt I've read but didn't understand cause I have no practice in creating plugins.

Could anyone show me the code examples (plugandpaint example I saw)

Thanks!

wysota
4th July 2006, 09:29
What kind of plugin functionality do you need? Could you give more details? Did you try anything on your own? What problems did occur?

gfunk
4th July 2006, 09:45
Have you read the plugin howto page yet?
http://doc.trolltech.com/4.1/plugins-howto.html

fullmetalcoder
4th July 2006, 09:51
Creating plugins is quite simple if you know what you want to do, and, as always with Qt the docs are quite complete.

Qt plugin system is based on interfaces. They are defined in header files of your app, contain only pure virtual function and use the Q_DECLARE_INTERFACE macro to correctly "register" into Meta Object system.

Plugins are centered around a class that inherits from QObject and interfaces that need to be implemented. The Q_INTERFACES macro is used to declare which interfaces are used.
The Q_EXPORT_PLUGIN2 macro infor the Meta Object system about which class has to be considered as root component, (it probably creates a static pointer but I've not looked to deep into that)...

Loading such plugins simply need to create a QPluginLoader with the name of the plugin you want to load. the instance() function return a pointer to the root component of the loaded plugin. This QObject can be casted to interfaces thanks to the macros you used and these interfaces can then be used as if they had been created in the app...

If you want a more concrete examples of plugins and that plug and paint examples doesn't satisfy you, check out Edyuk sources (http://sourceforge.net/project/showfiles.php?group_id=168260).

Chaid
4th July 2006, 11:52
I want my future plugins to do following:
-parse files
- return title and etc...

wysota
4th July 2006, 15:07
But did you already try anything? Have you read the plugin howto?