Ok, I think my confusion came from the fact, that I thought the plugin must somehow inherit from QObject and can't be just QWidget only . However, in that case I don't really need a createWidget function?
I was thinking of doing something like this now:
class ViewPluginInterface
: public QWidget // to ensure, that anyone using this interface, is creating it as a QWidget{
...
};
Q_DECLARE_INTERFACE( ViewPluginInterface, "..." )
class ViewPluginInterface : public QWidget // to ensure, that anyone using this interface, is creating it as a QWidget
{
...
};
Q_DECLARE_INTERFACE( ViewPluginInterface, "..." )
To copy to clipboard, switch view to plain text mode
class SomeCustomViewPluginForTheApp : public ViewPluginInterface
{
Q_OBJECT
Q_INTERFACES( ViewPluginInterface )
...
};
class SomeCustomViewPluginForTheApp : public ViewPluginInterface
{
Q_OBJECT
Q_INTERFACES( ViewPluginInterface )
...
};
To copy to clipboard, switch view to plain text mode
And then at some point in the main application
if ( !pluginDir.cd( "plugins" ) )
return;
foreach
( QString fileName, pluginDir.
entryList( QDir::Files ) ){
if ( ViewPluginInterface *interface = qobject_cast<ViewPluginInterface*>( loader.instance() ) )
{
// this should be a ViewPluginInterface instance, which in turn is a QWidget instance
...
}
}
QDir pluginDir( QApplication::applicationDirPath() );
if ( !pluginDir.cd( "plugins" ) )
return;
foreach( QString fileName, pluginDir.entryList( QDir::Files ) )
{
QPluginLoader loader( pluginDir.absoluteFilePath( fileName ) );
if ( ViewPluginInterface *interface = qobject_cast<ViewPluginInterface*>( loader.instance() ) )
{
// this should be a ViewPluginInterface instance, which in turn is a QWidget instance
...
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks