Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Plugin with signals and slots [SOLVED]

    General and Desktop
    plugin signal slots
    2
    6
    6452
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • dnasta
      dnasta last edited by dnasta

      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,

      1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • dnasta
          dnasta last edited by dnasta

          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,

          1 Reply Last reply Reply Quote 0
          • dnasta
            dnasta 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 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,

            1 Reply Last reply Reply Quote 1
            • mrjj
              mrjj Lifetime Qt Champion last edited by

              super,
              thank you for updating.

              1 Reply Last reply Reply Quote 0
              • dnasta
                dnasta 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

                1 Reply Last reply Reply Quote 2
                • First post
                  Last post