[solved] Object::connect: No such slot



  • I modified the example "Configuration Dialog" (from Qt 4.8/ creator2.8)
    for learning by doing. On a QPushbutton clicked event on one of the pages
    of a QStackedWidget a short message should be printed out.
    I'm not able to set the connect SIGNAL correctly. What is wrong here ?
    @class TestPage : public QWidget
    {
    public:
    TestPage(QWidget *parent = 0);

    private:
    QPushButton *pb_1 ;
    QPushButton *pb_2 ;
    QPushButton *pb_go;

    private slots:
    void xxx();

    };@

    @TestPage::TestPage(QWidget *parent)
    : QWidget(parent)
    {

    QGroupBox *gb_avalPorts = new QGroupBox("Availabe ports");
    
    pb_1 = new QPushButton("1");
    pb_2 = new QPushButton("2");
    
    QVBoxLayout *sniffLayout = new QVBoxLayout;
    sniffLayout->addWidget(pb_1);
    sniffLayout->addWidget(pb_2);
    gb_avalPorts->setLayout(sniffLayout);
    
    pb_go = new QPushButton("Go");
    
    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(gb_avalPorts);
    mainLayout->addWidget(pb_go);
    mainLayout->addSpacing(12);
    

    // mainLayout->addStretch(1);
    setLayout(mainLayout);

    connect(pb_go, SIGNAL(clicked()), this, SLOT(xxx()));
    

    }

    void TestPage::xxx()
    {
    qDebug() << "bingo";

    }
    @

    immediately on startup i get message:
    Object::connect: No such slot QWidget::xxx()


  • Lifetime Qt Champion

    Hi,

    You are missing the Q_OBJECT macro in your class declaration



  • Never would find this without your hint, thx.
    but now:
    pages.cpp:-1: error: undefined reference to `vtable for TestPage'

    i just addes line 3

    @class TestPage : public QWidget
    {
    Q_OBJECT

    public:
    TestPage(QWidget *parent = 0);

    private:
    QPushButton *pb_1 ;
    QPushButton *pb_2 ;
    QPushButton *pb_go;

    private slots:
    void xxx();

    };@


  • Lifetime Qt Champion

    You need to run qmake when you add/remove the Q_OBJECT macro before building


  • Moderators

    Probably a good idea to "rerun qmake" and "rebuild".



  • Yup ! Great ! Thank you !


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.