PDA

View Full Version : Why can Qt Creator use QPluginLoader to load plugins?



MorrisLiang
24th April 2010, 17:26
I'm new to qt,forgive me if this is a stupid question.

I checked the qt creator source code.And noticed that in the libs/extensionsystem/pluginspec.cpp, it use QPluginLoader to load the dll file.The plugins are subclasses of IPlugin.

I also read the help/tutorial,isn't that we have to use some macros like,Q_EXPORT_PLUGIN2(),Q_INTERFACES() if we want to create application plugins?And if we don't use these macros,the QPluginLoader won't load the dll file,right?

So,in the qtcreator,how does the PluginSpec class enable to load the plugin dll files with QPluginLoader?:confused:

ABBAPOH
24th April 2010, 20:49
Q_INTERFACES and Q_DECLARE_INTERFACE enable qobject_cast to interface, ie IFace * face = qobject_cast<IFace *>(pluginClass);
If pluginClass inherits QObject, these macroses are not needed.
But Q_EXPORT_PLUGIN2 or Q_EXPORT_PLUGIN creates functions that are exported from plugin - these functions create instance of your exported class. Yes, without one of them plugin won't work.

MorrisLiang
25th April 2010, 05:07
But qt creator didn't use these macros...lol

ABBAPOH
25th April 2010, 09:26
in qtcreator all interfaces are subclasses of QObject - they don't need first macro
and second is used: file src/plugins/bineditor/bineditorplugin.cpp

Q_EXPORT_PLUGIN(BinEditorPlugin)

MorrisLiang
25th April 2010, 17:00
OK,I miss that part,Thanks for pointing that out.I'll check for that..:)