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. Signals/Slots: GUI + Plugin Interface (API)
Forum Updated to NodeBB v4.3 + New Features

Signals/Slots: GUI + Plugin Interface (API)

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 1.2k Views 1 Watching
  • 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.
  • F Offline
    F Offline
    fem_dev
    wrote on last edited by
    #1

    Hi, I would like to connect my UI Form Button to a Plugin API class slot function...but I got some Qt IDE erros:
    My plugin class is called "Analysis X":

    class ANALYSIS_XSHARED_EXPORT Analysis_x: public QObject, public Plugin_API
    {
        Q_OBJECT
        Q_PLUGIN_METADATA(IID "com.lamar.plugin")
        Q_INTERFACES(Plugin_API)
     
    public:
        explicit Analysis_x(QObject* parent = nullptr);
        ~Analysis_x() override;
     
        void run(void) override;
     
    private:
        Form* _form;
     
    public slots:
        void onMessage(QString msg);
    };
    

    My plugin GUI is a Form Class:

    class Form : public QWidget
    {
        Q_OBJECT
     
    public:
        explicit Form(QWidget *parent = nullptr);
        ~Form();
     
    signals:
        void mySignal(QString msg);
     
    private slots:
        void on_save_btn_clicked();
     
    private:
        Ui::Form *ui;
    };
    

    So, I tried to connect both using:

    
    void Analysis_x::run()
    {
        qInfo() << "RUNNING: analysis X";
        _form = new Form();
        _form->show();
        _form->connect(&_form, &_form->mySignal, &this, &this->onMessage);
    }
    

    But I got this errors:

    analysis_x.cpp:62:28: error: cannot create a non-constant pointer to member function
    analysis_x.cpp:62:46: error: cannot take the address of an rvalue of type 'Analysis_x *'
    analysis_x.cpp:62:53: error: cannot create a non-constant pointer to member function
    

    What I have to do to connect these QObjects?

    1 Reply Last reply
    0
    • mrjjM mrjj

      @fem_dev
      hi you are mixing old and new syntax :)
      try
      form->connect(_form, &Form::mySignal, this, &Analysis_x::onMessage);

      F Offline
      F Offline
      fem_dev
      wrote on last edited by
      #7

      @mrjj perfect! Thank you! You are great!

      1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @fem_dev said in Signals/Slots: GUI + Plugin Interface (API):

        _form->connect(&_form, &_form->mySignal, &this, &this->onMessage);

        The syntax is more like
        _form->connect(_form, &Form::mySignal, this, this->onMessage);
        Too many & and you must use the class name and not the instance for the function pointer.

        F 1 Reply Last reply
        0
        • mrjjM mrjj

          @fem_dev said in Signals/Slots: GUI + Plugin Interface (API):

          _form->connect(&_form, &_form->mySignal, &this, &this->onMessage);

          The syntax is more like
          _form->connect(_form, &Form::mySignal, this, this->onMessage);
          Too many & and you must use the class name and not the instance for the function pointer.

          F Offline
          F Offline
          fem_dev
          wrote on last edited by
          #3

          @mrjj said in Signals/Slots: GUI + Plugin Interface (API):

          _form->connect(_form, &Form::mySignal, this, this->onMessage);

          I tried it now, but I got:

          analysis_x.cpp:63:56: error: reference to non-static member function must be called
          
          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #4

            Hi
            did you use the keyword static in any place ?
            als do you have the body defined for
            void onMessage(QString msg);

            else check the syntax again
            https://wiki.qt.io/New_Signal_Slot_Syntax

            Update:
            sorry, too hot.
            The last part is also incorrect

            _form->connect(_form, &Form::mySignal, this, &Analysis_x::onMessage);

            F 1 Reply Last reply
            0
            • mrjjM mrjj

              Hi
              did you use the keyword static in any place ?
              als do you have the body defined for
              void onMessage(QString msg);

              else check the syntax again
              https://wiki.qt.io/New_Signal_Slot_Syntax

              Update:
              sorry, too hot.
              The last part is also incorrect

              _form->connect(_form, &Form::mySignal, this, &Analysis_x::onMessage);

              F Offline
              F Offline
              fem_dev
              wrote on last edited by
              #5

              @mrjj
              No, I don't use the keyword static in any place.

              I defined void onMessage(QString msg); because I'm sending a message from a clicked button to my Plugin API:

              My Signal implemetation:

              void Form::on_save_btn_clicked()
              {
                  emit mySignal("Save");
              }
              

              My Slot implementation:

              void Analysis_x::onMessage(QString msg)
              {
                  qInfo() << "My msg: " << msg;
              }
              

              What I'm doing wrong?

              mrjjM 1 Reply Last reply
              0
              • F fem_dev

                @mrjj
                No, I don't use the keyword static in any place.

                I defined void onMessage(QString msg); because I'm sending a message from a clicked button to my Plugin API:

                My Signal implemetation:

                void Form::on_save_btn_clicked()
                {
                    emit mySignal("Save");
                }
                

                My Slot implementation:

                void Analysis_x::onMessage(QString msg)
                {
                    qInfo() << "My msg: " << msg;
                }
                

                What I'm doing wrong?

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @fem_dev
                hi you are mixing old and new syntax :)
                try
                form->connect(_form, &Form::mySignal, this, &Analysis_x::onMessage);

                F 1 Reply Last reply
                2
                • mrjjM mrjj

                  @fem_dev
                  hi you are mixing old and new syntax :)
                  try
                  form->connect(_form, &Form::mySignal, this, &Analysis_x::onMessage);

                  F Offline
                  F Offline
                  fem_dev
                  wrote on last edited by
                  #7

                  @mrjj perfect! Thank you! You are great!

                  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