[Interest] Doubt extending my app functions ability

Bob Hood bhood2 at comcast.net
Thu Jan 12 21:29:14 CET 2017


On 1/12/2017 6:23 AM, Ernesto wrote:
>
> Hello to everyone,
>
> My name is Ernesto. I am a beginner in Qt programming and I have an 
> specifics problems whit my first big project (desktop app). Let me explain 
> myself:
>
> I have to include plugins or add-ons to my application for new file format 
> types; I looked around QPluginLoader class, Dynamic and Static libraries 
> classes to achieve this goal, and here is my problem, in each one of this I 
> have to include the header file and the library (or plugins) in my project. 
> I have to develop other mini app to create those plugins or libraries. So 
> here is _my first problem_, I donĀ“t know how many plugins or libraries will 
> be development to include in my app.
>

Hello, Ernesto.

I will not address your entire problem (because I'm not clearly understanding 
the second one), but your first is easy enough to answer.  The answer is:  You 
don't /need/do know how many plug-ins will be in development.

Plug-ins, by definition, are external code to your main application.  You 
application needs to /discover/those pieces of external code when it runs.  
This way, any number of plug-ins can be included with your application--or 
even added later by the user to an existing installation of your 
application--without having to modify any of your main application's code.

For example, when your main application starts, it looks in a location--either 
hard-coded, or defined by the user--and discovers all the available shared 
libraries:

     ...
     QDir plugins("ernestos_plugins");
     QStringList plugins_list = plugins.entryList(QStringList() << "*.dll" << 
"*.so", QDir::Files);
     ...

With each shared library it finds, it tests each to see if it is a plug-in 
designed for your application by coercing it to the interface contract, 
something like:

     foreach(const QString& filename, plugins_list)
     {
         QString plugin_path = 
QDir::toNativeSeparators(QString("%1/%2").arg(plugins.absolutePath()).arg(filename));
         QPluginLoader(plugin_path);
         QObject* instance = plugin.instance();
         if(instance)
         {
             IErnestoPlugin* iernestofactory = 
reinterpret_cast<IErnestoPlugin*>(instance);
             if(iernestofactory)
             {
                 ...

Each one that supports the contract of your interface ("IErnestoPlugin") can 
be safely used within your application as a plug-in designed for your main 
application.

I hope I understood the first problem correctly.  Apologies if I didn't.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170112/4acc3131/attachment.html>


More information about the Interest mailing list