Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Signal, Slot and QtPlugin
QtWS25 Last Chance

[Solved] Signal, Slot and QtPlugin

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.7k Views
  • 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 Offline
    L Offline
    lady_freyja
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • L Offline
        L Offline
        lady_freyja
        wrote on last edited by
        #3

        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
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          0
          • L Offline
            L Offline
            lady_freyja
            wrote on last edited by
            #5

            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
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved