[Interest] Finally about extends my app function ability

Ernesto ernestoac at icrt.cu
Mon Jan 16 03:09:18 CET 2017


Hello, thanks again to /Bob Hood/, /Konstantin Tokarev/ and /Thiago 
Macieira/.

Well, in my previous mail, I show you an example project to test my 
doubts about extending app through plugin addition (in this case from 
Static Library). After reading all yours considerations several 
occasions and reading Qt Documentation about plugins. I included the 
plugin correctly in my MainApp.

Here is the code:

//This is header file of *Lib1*

#include"lib1_global.h"

#include<QObject>

#include<QDebug>

#include<QtPlugin>

#include"../pinterface.h"

classLib1:publicQObject,publicPInterface *_//here I have to include the 
inherit of QObject and its macro_*

{

Q_OBJECT

Q_PLUGIN_METADATA(IID"org.Ernesto.Plugin")

*_//here I miss the plugin metadata ID and allow me instantiate this 
object_**__*

Q_INTERFACES(PInterface)

public:

Lib1();

QString/Name/()const;

};

//This is cpp file of *Lib1*

QStringLib1::/Name/()const

{

return"HellofromDLL";

}

//This is cpp file of *MainApp*

MainWindow::MainWindow(QWidget*parent):QMainWindow(parent),ui(newUi::MainWindow)

{

QDirplugins("C:/lib/");

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

foreach(QStringfilename,plugins_list) *_//In this structure I abbreviated_*

{

QStringplugin_path=QDir::toNativeSeparators(QString("%1/%2").arg(plugins.absolutePath()).arg(filename));

QPluginLoaderpl(plugin_path);

*_//My problem was the cast type, I was usin reinterpret_cast and now 
dynamic_cast_*

if(PInterface*myInterface=dynamic_cast<PInterface*>(pl.instance()))

ui->label->setText(myInterface->/Name/());

}

}

**

//This is header file of my interface, is included by both projects

classPInterface *_//this class was inheriting of QObject, and as Lib1 
inherits of PInterface and QObject, so PInterface can´t inherits of 
QOjects; and of course I deleted the constructor and O_OBJECT macro._*

{

public:

virtualQString/Name/()const=0;

};

Q_DECLARE_INTERFACE(PInterface,"org.Ernesto.Plugin")

I can´t found an explanation of the differences of /reinterpret_cast/ 
and /dynamic_cast/, because I can´t found information about 
/reinterpret_cast/ in Qt Documentation (5.5.0 Qt version).

I thanks to /Steven Davidson/ (from /cconclase/ list), who four years 
ago taught me the /dynamic_cast/ use.

Regards,

Ernesto

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170116/69b7ecec/attachment.html>


More information about the Interest mailing list