Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to connect SIGNAL(clicked()) of QPushButton to inherited class MyPushButton to SLOT -> executeMe().

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

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Aditya1309
    wrote on last edited by VRonin
    #1
    #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

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Just add the connect in MyPushButton's constructor.

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

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      1
      • A Offline
        A Offline
        Aditya1309
        wrote on last edited by
        #3

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

        1 Reply Last reply
        1
        • Maarouf Med MahdiM Offline
          Maarouf Med MahdiM Offline
          Maarouf Med Mahdi
          wrote on last edited by
          #4

          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() ) );

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved