Important: Please read the Qt Code of Conduct -

How to connect SIGNAL(clicked()) of QPushButton to inherited class MyPushButton to SLOT -> executeMe().

  • #ifndef MYPUSHBUTTON_H
    #define MYPUSHBUTTON_H
    #include <QDebug>
    #include <QPushButton>
    class MyPushButton : public QPushButton
        explicit MyPushButton(QString str, QWidget *parent = 0);
        void mousePressEvent(QMouseEvent *);
        void myclick();
        void clickMe();
    private slots:
        void executeMe();
    #endif // MYPUSHBUTTON_H

    My Requirement to connect

  • Just add the connect in MyPushButton's constructor.

    Probably you don't want the constructor to be explicit

  • Fine,
    I forgot to add Q_OBJECT,
    class MyPushButton : public QPushButton

  • hi, I aleardy got that ,
    to connect a Sigal-slot in qt you need add in the constructor :
    connect ( this , SIGNAL( clicked() ), this , SLOT( executeMe() ) );

Log in to reply