Nominate our 2022 Qt Champions!

No such slot

  • Something I don't understand about slots i guess . My slot function never gets called .
    I see a message that says :
    QObject::connect: No such slot Lobby::Lobby::onMyButtonClick() in lobby.cpp:13

    @#pragma once

    #include <QtWidgets/QWidget>

    class Lobby : public QWidget


    Lobby(QWidget *parent = 0);

    void keyPressEvent(QKeyEvent * e);
    void closeEvent(QCloseEvent * e);

    public slots:
    void onMyButtonClick();


    #include <QPushButton>
    #include <QApplication>
    #include <QKeyEvent>
    #include "lobby.h"

    Lobby::Lobby(QWidget *parent)
    : QWidget(parent)
    QPushButton *myButton = new QPushButton("button", this);
    myButton->setGeometry(50, 40, 75, 30);

    connect(myButton, SIGNAL(clicked()), this, SLOT(Lobby::onMyButtonClick()));

    void Lobby::onMyButtonClick()



  • Never mind ... I changed Lobby::onMyButtonClick() to onMyButtonClick() and it works now . I originally had onMyButtonClick() and wasn't working either so I am not sure what was the fix though .

  • Lifetime Qt Champion


    The SLOT and SIGNAL function signatures must not contain the class name, only the function name and argument types.

Log in to reply