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] Slot is not recognized

[Solved] Slot is not recognized

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 1.8k 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.
  • S Offline
    S Offline
    silep
    wrote on last edited by
    #1

    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
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

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

        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
        0
        • S Offline
          S Offline
          silep
          wrote on last edited by
          #4

          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
          0
          • JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            [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
            0
            • X Offline
              X Offline
              Xander84
              wrote on last edited by
              #6

              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
              0
              • S Offline
                S Offline
                silep
                wrote on last edited by
                #7

                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
                0

                • Login

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