Plugin with signals and slots [SOLVED]



  • 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,


  • Qt Champions 2016

    Hi
    As far as I know, its possible.

    I found a sample here
    http://www.qtcentre.org/archive/index.php/t-56135.html

    look for "The following code builds plugin lib "
    ca. middle of page.



  • 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,



  • 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 connect

    In 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,


  • Qt Champions 2016

    super,
    thank you for updating.



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.