Qt Forum

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

    Call for Presentations - Qt World Summit

    [Solved] Signal, Slot and QtPlugin

    General and Desktop
    2
    6
    2328
    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.
    • L
      lady_freyja last edited by

      Hello,

      I've run into an odd issue, and I don't find where the problem is.
      First of all : I'm on Qt 5.2.1 with MVS2010.

      My application do some heavy stuff, so one side I have my GUI and other side I have the heavy stuff in a thread called "processeur".
      This thread use many plugins from the same interface. And I want that plugins send log messages to the GUI.
      So my thread loads and uses the plugin, the plugin emits a signal, catched by the thread, who transmit by sending another signal to the GUI.

      Here my code :

      The Interface, "FournitureBancInterface" :
      @
      #include "fourniturebancinterface_global.h"

      class FOURNITUREBANCINTERFACESHARED_EXPORT FournitureBancInterface : public QObject
      {
      Q_OBJECT

      protected:
      FournitureBancInterface();

       virtual int verification(int niveau) = 0;
      

      signals:
      void logMessage(const QString &msg);

      };

      Q_DECLARE_INTERFACE(FournitureBancInterface, "blabla.FournitureBancInterface")
      @

      The plugin "Ute" :
      @
      #include "../fourniturebancinterface/fourniturebancinterface.h"

      class Ute : public FournitureBancInterface
      {
      Q_OBJECT
      Q_PLUGIN_METADATA(IID "blabla.FournitureBancInterface" FILE "ute.json")
      Q_INTERFACES(FournitureBancInterface)

      public:
      Ute() {}

      int verification(int niveau);
      

      };

      int Ute::verification(int niveau)
      {
      int state = codeErreurs::NO_ERROR;

      emit logMessage("NUMINIT");
      
      return state;
      

      }
      @

      And then, my thread "Processeur" :
      @
      #include "../format_banc/fourniturebancinterface/fourniturebancinterface.h"

      class Processeur : public QThread
      {
      Q_OBJECT

      public:

      Processeur(int niveau, QString adresseDir, int bancID, bool codage);
      ~Processeur() {}
      
      void run();
      

      private:
      FournitureBancInterface *loadPlugin(QString driverName);

      signals:
      void logMessage(const QString &msg);

      public slots:
      void handleLogMessage(const QString &msg);

      };

      void Processeur::handleLogMessage(const QString &msg)
      {
      emit logMessage(msg);
      }

      void Processeur::run()
      {
      FournitureBancInterface *piloteUte=NULL;

      piloteUte = loadPlugin("ute.dll");
      connect(piloteUte, SIGNAL(logMessage(QString)), this, SLOT(handleLogMessage(QString)));
      piloteUte->verification(niveauVerif);
      

      }
      @

      The code compiles, the connect() in the thread returns "true", and the signal is well emited.
      But if I place a breakpoint in Processeur::handleLogMessage(), it's never reached, as if the "processeur" never see any signal from my plugin.

      I'm working on this since 2 days, having a signal emited from the plugins catched by the "processeur". It's my second solution which compile but didn't works (and many other which didn't compile at all...) I'm totally out of idea.
      Any help?

      Regards,
      Julia.

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

        Hi and welcome to devnet,

        How do you know that logMessage is correctly emitted ?

        On a side note, you can avoid the intermediate handleLogMessage slot by connecting Ute's logMessage directly to Processor logMessage

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • L
          lady_freyja last edited by

          Thank for the reply.

          [quote author="SGaist" date="1398716338"]How do you know that logMessage is correctly emitted ?[/quote]
          I caught it with a slot, directly in the Ute plugin.

          [quote author="SGaist" date="1398716338"]On a side note, you can avoid the intermediate handleLogMessage slot by connecting Ute's logMessage directly to Processor logMessage[/quote]
          Oh, I didn't know we can do this, it's a nice thing. :)

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

            Just realized…

            Using QThread like that, at the end of run your thread is stopped. Have a look at the the latest Qt 5 QThread documentation. You'll see how to implement the worker object technique with QThread

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • L
              lady_freyja last edited by

              Hey! Now everything works!
              Thanks!

              Yep, initialy I've implemented the "another way" described in QThread documentation.
              Now, I have implemented the thread with the worker technique. And the signal is well caught by the processor.

              I don't understand why it's works with the worker and didn't with the "another way". Is there a reason about this?

              Anyway, thanks again. :)

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

                I don't know about the rest of your program, but implementing run like that you did would just do what's written in run and then the end, the thread is already stopped since you don't have any while loop or event loop running.

                You're welcome !

                Happy coding :)

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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