Plugin with signals and slots [SOLVED]
-
wrote on 7 Sept 2015, 18:55 last edited by dnasta 9 Sept 2015, 16:51
Hello good afternoon,
A plugin can have signals and slots that are caught and emited by the application that load?
I find no documentation or example,
Thank you,
Cheers,
-
Hi
As far as I know, its possible.I found a sample here
http://www.qtcentre.org/archive/index.php/t-56135.htmllook for "The following code builds plugin lib "
ca. middle of page. -
wrote on 9 Sept 2015, 04:06 last edited by dnasta 9 Sept 2015, 04:47
Hello mrjj,
thanks for the reply,
my plugin implementation is somewhat different, that's why when I add Q_OBJECT the interface, not compiled dll (unresolved external symbol)
this is the implementation with Q_OBJECT
class PluginPruebaInterfaz : public QObject { Q_OBJECT public: virtual ~PluginPruebaInterfaz() {} virtual QString retornaCadenaInvertida(QString cadena) = 0; signals: void senial(QString cadena); }; class PluginPrueba : public PluginPruebaInterfaz, public OtroPluginInterfaz, public TercerPluginInterfaz { Q_OBJECT Q_PLUGIN_METADATA(IID "xxx.PluginPruebaInterfaz") Q_INTERFACES(PluginPruebaInterfaz OtroPluginInterfaz TercerPluginInterfaz) ClasePluginPrueba *plgPrueba; ClaseOtroPlugin *plgOtro; ClaseTercerPlugin *plgTercero; public: PluginPrueba(); ~PluginPrueba(); QString retornaCadenaInvertida(QString cadena); bool retornaNegacion(bool valor); qint64 retornaNegativoPositivo(qint64 valor); };
this implementation is that works
class PluginPruebaInterfaz { public: virtual ~PluginPruebaInterfaz() {} virtual QString retornaCadenaInvertida(QString cadena) = 0; }; class PluginPrueba : public QObject, public PluginPruebaInterfaz, public OtroPluginInterfaz, public TercerPluginInterfaz { Q_OBJECT Q_PLUGIN_METADATA(IID "xxx.PluginPruebaInterfaz") Q_INTERFACES(PluginPruebaInterfaz OtroPluginInterfaz TercerPluginInterfaz) ClasePluginPrueba *plgPrueba; ClaseOtroPlugin *plgOtro; ClaseTercerPlugin *plgTercero; public: PluginPrueba(); ~PluginPrueba(); QString retornaCadenaInvertida(QString cadena); bool retornaNegacion(bool valor); qint64 retornaNegativoPositivo(qint64 valor); };
Thank you,
Greetings,
-
wrote on 9 Sept 2015, 04:58 last edited by
I found this post and I could implement a signal emitted from the dll
I declared in the interface
virtual QObject * getObject () = 0;
for the QObject that requires connectIn the implementation, I added
QObject* getObject() { return this; } signals: void senial(QString cadena);
And I connected with
connect( plgItfz->getObject(), SIGNAL(senial(QString)), this, SLOT(senialRecibida(QString)) );
the next step is send a signal from the application and receive the plugin
Thank you,
Greetings,
-
super,
thank you for updating. -
wrote on 9 Sept 2015, 16:50 last edited by
Hello good afternoon,
When I go to the forum to solve a problem it is because I could not find anything on the web, but in this case was too simple theme, perhaps only experiencing what he had resolved because it is too simple to implement signals and slots between the application and the dll
To end the post: to implement the slot in the plug receiving a signal from the application, add the virtual interface slot
public slots: virtual void disparador(QString texto) = 0;
and I made in the implementation of the interface
public slots: void disparador(QString texto);
to connect to the application, I used getObject
connect( this, SIGNAL(disparaTexto(QString)), plgItfz->getObject(), SLOT(disparador(QString)) );
Thank you
greetings
-
Hello good afternoon,
When I go to the forum to solve a problem it is because I could not find anything on the web, but in this case was too simple theme, perhaps only experiencing what he had resolved because it is too simple to implement signals and slots between the application and the dll
To end the post: to implement the slot in the plug receiving a signal from the application, add the virtual interface slot
public slots: virtual void disparador(QString texto) = 0;
and I made in the implementation of the interface
public slots: void disparador(QString texto);
to connect to the application, I used getObject
connect( this, SIGNAL(disparaTexto(QString)), plgItfz->getObject(), SLOT(disparador(QString)) );
Thank you
greetings
wrote on 14 Jun 2023, 13:07 last edited by@dnasta I have found simple example with similar implementation.
But anyway, this is old school syntax ofconnect
, with new syntax it doesn't work.