Qt Forum

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

    Call for Presentations - Qt World Summit

    [Solved] Slot is not recognized

    General and Desktop
    4
    7
    1446
    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.
    • S
      silep last edited by

      Hello,

      I have a small problem with a slot, my connect doesn't work because
      @QObject::connect: No such slot ctrlMachine::MainForm::onAxis_error(QString) in .\ctrlMachine.cpp:94@
      I think that I have to find another way to write my slot, but I also tried with an object, without changes.

      ctrlMachine.cpp:
      @#include "ctrlMachine.h"

      this->connect(axisCamX, SIGNAL( signalError(QString) ), SLOT(MainForm::onAxis_error(QString)));@
      ctrlMachine.h:
      @#include "mainform.h"

      class ctrlMachine : public QObject {.....etc }; @
      mainform.cpp:
      @#include "mainform.h"
      #include "ctrlMachine.h"

      void MainForm::onAxis_error(QString msg)
      {
      QMessageBox msgBox;
      msgBox.setText("ERROR");
      msgBox.setInformativeText( msg );
      msgBox.setIcon(QMessageBox::Critical);
      msgBox.setStandardButtons(QMessageBox::Close);
      msgBox.setDefaultButton(QMessageBox::Close);
      msgBox.exec();
      }
      @
      mainform.h:
      @#include "ui_mainform.h"

      class ctrlMachine;

      class MainForm : public QMainWindow
      {
      Q_OBJECT

      public slots:
      void onAxis_error(QString msg);

      private:

      Ui::MainForm *ui;
      ctrlMachine *machine; ....etc };@
      Is "MainForm::onAxis_error(QString)" right in my slot? Would anyone know how to solve the problem? Thank you in advance

      1 Reply Last reply Reply Quote 0
      • JKSH
        JKSH Moderators last edited by

        Hi,

        There are 2 issues with your connect() statement:

        You forgot to include the pointer to your MainForm object.

        You shouldn't write the "MainForm::" in front of "onAxis_error".

        @
        this->connect(axisCamX, SIGNAL(signalError(QString)),
        mainForm, SLOT(onAxis_error(QString)));
        @

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

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

          On top of what JKSH already said, the MainForm class needs the Q_OBJECT macro.

          https://forum.qt.io/category/41/romanian

          1 Reply Last reply Reply Quote 0
          • S
            silep last edited by

            Thank you for your replies! Sorry Zlatomir, the Q_OBJECT is already there, I just forgot to copy it.

            JKSH: Do you mean the pointer this? How can I add it to my MainForm? I don't understand

            1 Reply Last reply Reply Quote 0
            • JKSH
              JKSH Moderators last edited by

              [quote author="silep" date="1397649969"]JKSH: Do you mean the pointer this? How can I add it to my MainForm? I don't understand[/quote]See the code in my previous post. There are 4 arguments (but your code only has 3). The syntax is

              @
              connect(pointerToSender, SIGNAL(nameOfSignal()),
              pointerToReceiver, SLOT(nameOfSlot()));
              @

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply Reply Quote 0
              • X
                Xander84 last edited by

                Just to clarify there is an overload of the "old" QObject::connect function that takes only 3 arguments, if the slot is the defined in the same QObject class.

                @
                connect(sender, SIGNAL(...), this, SLOT(...));
                // should be the same as
                connect(sender, SIGNAL(...), SLOT(...));
                @

                As far as I know that only works for the old connect syntax, if you are using Qt5 with function pointers you have to use 4 arguments I think.

                1 Reply Last reply Reply Quote 0
                • S
                  silep last edited by

                  Thank you, it seems to work now. I thought that the pointer this replaced the mainform pointer, but it is not the case

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