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. QPushButton in a QFrame does not receive clicked signle.
Forum Updated to NodeBB v4.3 + New Features

QPushButton in a QFrame does not receive clicked signle.

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 7 Posters 943 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.
  • R Offline
    R Offline
    ryman
    wrote on last edited by
    #1

    I have a QPushButton in a QFrame, and add code below in the mainwindow constructor.
    企业微信截图_7aa40070-cf9c-4bfc-b3da-ba06fddbc0f9.png e url)

    connect(ui->btn_close, &QPushButton::clicked, this, [=]{
        qDebug(" button is clicked");
    });
    

    But when I clicked button, no clicked single was received. What's the problem? Thanks!

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tannhaus
      wrote on last edited by tannhaus
      #2

      I might not be helpful....but aren't you missing the () in your lambda?

      connect(ui->btn_close, &QPushButton::clicked, this, [=](){
          qDebug(" button is clicked");
      });
      
      R 1 Reply Last reply
      1
      • T tannhaus

        I might not be helpful....but aren't you missing the () in your lambda?

        connect(ui->btn_close, &QPushButton::clicked, this, [=](){
            qDebug(" button is clicked");
        });
        
        R Offline
        R Offline
        ryman
        wrote on last edited by
        #3

        @tannhaus
        I added this keyword , the problem is not resovled.

        T JonBJ 2 Replies Last reply
        0
        • R ryman

          @tannhaus
          I added this keyword , the problem is not resovled.

          T Offline
          T Offline
          tannhaus
          wrote on last edited by
          #4

          @ryman

          The following code works:

          connect(ui->btn_close, &QPushButton::clicked, this, [=](){qDebug() << "Button is clicked";});
          
          1 Reply Last reply
          1
          • R ryman

            @tannhaus
            I added this keyword , the problem is not resovled.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @ryman said in QPushButton in a QFrame does not receive clicked signle.:

            @tannhaus
            I added this keyword , the problem is not resovled.

            It's not this which is at issue. As @tannhaus has shown you, it is parentheses you are missing, please copy & paste his code.

            qwasder85Q 1 Reply Last reply
            0
            • JonBJ JonB

              @ryman said in QPushButton in a QFrame does not receive clicked signle.:

              @tannhaus
              I added this keyword , the problem is not resovled.

              It's not this which is at issue. As @tannhaus has shown you, it is parentheses you are missing, please copy & paste his code.

              qwasder85Q Offline
              qwasder85Q Offline
              qwasder85
              wrote on last edited by qwasder85
              #6

              @JonB said in QPushButton in a QFrame does not receive clicked signle.:

              @ryman said in QPushButton in a QFrame does not receive clicked signle.:

              @tannhaus
              

              I added this keyword , the problem is not resovled.

              It's not this which is at issue. As @tannhaus has shown you, it is parentheses you are missing, please copy & paste his code.

              You might even have to put the bool-parameter (from the clicked-signal) into the parentheses.

              connect(ui->btn_close, &QPushButton::clicked, this, [=](bool){
                  qDebug(" button is clicked");
              });
              
              JonBJ Ketan__Patel__0011K 2 Replies Last reply
              0
              • qwasder85Q qwasder85

                @JonB said in QPushButton in a QFrame does not receive clicked signle.:

                @ryman said in QPushButton in a QFrame does not receive clicked signle.:

                @tannhaus
                

                I added this keyword , the problem is not resovled.

                It's not this which is at issue. As @tannhaus has shown you, it is parentheses you are missing, please copy & paste his code.

                You might even have to put the bool-parameter (from the clicked-signal) into the parentheses.

                connect(ui->btn_close, &QPushButton::clicked, this, [=](bool){
                    qDebug(" button is clicked");
                });
                
                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @qwasder85
                It is good style to do that anyway, but I thought (untested!) that when you have a lambda you can choose to omit parameters if you don't want them....

                1 Reply Last reply
                0
                • qwasder85Q qwasder85

                  @JonB said in QPushButton in a QFrame does not receive clicked signle.:

                  @ryman said in QPushButton in a QFrame does not receive clicked signle.:

                  @tannhaus
                  

                  I added this keyword , the problem is not resovled.

                  It's not this which is at issue. As @tannhaus has shown you, it is parentheses you are missing, please copy & paste his code.

                  You might even have to put the bool-parameter (from the clicked-signal) into the parentheses.

                  connect(ui->btn_close, &QPushButton::clicked, this, [=](bool){
                      qDebug(" button is clicked");
                  });
                  
                  Ketan__Patel__0011K Offline
                  Ketan__Patel__0011K Offline
                  Ketan__Patel__0011
                  wrote on last edited by
                  #8

                  @qwasder85

                  try this:

                  add this Code in Header File:

                  private slots:
                          void Click_Event_Of_CloseButton();
                  

                  add this Code in Source File

                  connect(ui->btn_close, SIGNAL(clicked()), this, SLOT(Click_Event_Of_CloseButton()));
                  

                  and write your code in Click_Event_Of_CloseButton function

                  MarKSM 1 Reply Last reply
                  0
                  • Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @ryman said in QPushButton in a QFrame does not receive clicked signle.:

                    But when I clicked button, no clicked single was received. What's the problem? Thanks!

                    Please provide a minimal, compilable example. I don't see why it should not work.

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    0
                    • Ketan__Patel__0011K Ketan__Patel__0011

                      @qwasder85

                      try this:

                      add this Code in Header File:

                      private slots:
                              void Click_Event_Of_CloseButton();
                      

                      add this Code in Source File

                      connect(ui->btn_close, SIGNAL(clicked()), this, SLOT(Click_Event_Of_CloseButton()));
                      

                      and write your code in Click_Event_Of_CloseButton function

                      MarKSM Offline
                      MarKSM Offline
                      MarKS
                      wrote on last edited by
                      #10

                      @Ketan__Patel__0011 OP states btn_close does not emit the clicked signal at all.

                      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