Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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
    {
    Q_OBJECT

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

    In mainform.cpp:
    @

    void MainForm::HandleOK()
    {
    ui->teErrorBrowser->insertPlainText("OK!!");
    this->close();
    }

    void MainForm::HandleCancel()
    {
    ui->teErrorBrowser->insertPlainText("Cancel!!");
    this->close();
    }

    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

    Hi,

    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