[Interest] Finally about extends my app function ability

Andy asmaloney at gmail.com
Mon Jan 16 14:30:30 CET 2017


On Sun, Jan 15, 2017 at 9:09 PM, Ernesto <ernestoac at icrt.cu> wrote:

> 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"
>
>
>
> class Lib1 : public QObject, public PInterface *//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*
>
> QString Lib1::*Name*() const
>
> {
>
>     return "Hello from DLL";
>
> }
>
>
>
> //This is cpp file of *MainApp*
>
> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),ui(new Ui::
> MainWindow)
>
> {
>
>     QDir plugins("C:/lib/");
>
>     QStringList plugins_list = plugins.entryList(QStringList() << "*.dll",
> QDir::Files);
>
>
>
>     foreach(QString filename, plugins_list) *//In this structure I
> abbreviated*
>
>     {
>
>         QString plugin_path = QDir::toNativeSeparators(QString("%1/%2"
> ).arg(plugins.absolutePath()).arg(filename));
>
>         QPluginLoader pl(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
>
> class PInterface *//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:
>
>     virtual QString *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).
>

You will probably find that Qt doesn't have much to say about them because
they are part of the C++ language.

  http://en.cppreference.com/w/cpp/language/dynamic_cast
  http://en.cppreference.com/w/cpp/language/reinterpret_cast

...and, since you're looking at casting, you should probably know about
const_cast and static_cast as well:

  http://en.cppreference.com/w/cpp/language/const_cast
  http://en.cppreference.com/w/cpp/language/static_cast


>
> I thanks to *Steven Davidson* (from *cconclase* list), who four years ago
> taught me the *dynamic_cast* use.
>
>
>
> Regards,
>
> Ernesto
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
---
Andy Maloney  //  https://asmaloney.com
twitter ~ @asmaloney <https://twitter.com/asmaloney>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170116/bd14f8fc/attachment.html>


More information about the Interest mailing list