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
    {
    public:
        MyPushButton();
        explicit MyPushButton(QString str, QWidget *parent = 0);
        void mousePressEvent(QMouseEvent *);
        void myclick();
    
    signals:
        void clickMe();
    private slots:
        void executeMe();
    
    };
    
    #endif // MYPUSHBUTTON_H
    

    My Requirement to connect



  • Just add the connect in MyPushButton's constructor.

    P.S.
    Probably you don't want the constructor to be explicit



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



  • 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
 

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