Important: Please read the Qt Code of Conduct -

[Solved] Slot not found

  • Hello, I wrote a signal/slot connect in a slot, but the debug doesn't find it.. It is written just before so I really don't know why. Here are my code lines:

    In mainform.h:

    @class MainForm : public QMainWindow

    private slots:
    void HandleOK();
    void HandleCancel();
    void on_pbChangeLensPlateXYScan_clicked();

    In mainform.cpp:

    void MainForm::HandleOK()

    void MainForm::HandleCancel()

    void MainForm::on_pbChangeLensPlateXYScan_clicked()
    QMainWindow mwLensPlateChoice = new QMainWindow(this);
    QDialogButtonBox bbValidation;
    definition of the two widgets...

    QPushButton* OkButton = bbValidation->button(QDialogButtonBox::Ok);
    connect(OkButton, SIGNAL(clicked()), mwLensPlateChoice, SLOT(HandleOK()));
    QPushButton* CancelButton = bbValidation->button(QDialogButtonBox::Cancel);
    connect(CancelButton, SIGNAL(clicked()), mwLensPlateChoice, SLOT(HandleCancel()));@

    The slots HandleOK() and HandleCancel() are not found..

  • Lifetime Qt Champion


    mwLensPlateChoice is a QMainWindow, not a MainForm

  • Thanks you for your reply! Yes you are right the slots are defined in MainForm, so I have to move them to qmainwindow.cpp? I hesitate to change the default files..

    Another solution should to change mwLensPlateChoice into a MainForm, because it is almost the same thing, but the method is in the MainForm class, so it doesn't work!

  • Lifetime Qt Champion

    You certainly should not touch QMainWindow for that.

    From your questions, you really should first look through Qt's documentation examples and tutorials.

  • I found another way, I just passed mwLensPlateChoice as a MainForm attribute, so that I can use it without input parameter in my slot functions, and put "this" for the receiver in my connect.

Log in to reply