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. The QPushButton clicked event in the dialog, could not call the slot
Forum Updated to NodeBB v4.3 + New Features

The QPushButton clicked event in the dialog, could not call the slot

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 1.8k Views 1 Watching
  • 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.
  • Z Offline
    Z Offline
    zJinWei
    wrote on last edited by
    #1

    When I click the mpLoginBtn button, nothing happen. Could you help me?
    @
    int main(int argc, char *argv[])
    {
    Q_INIT_RESOURCE(analyserec);
    QApplication a(argc, argv);

    CurllibPort port;
    MainWindow w;
    LoginDialog *pDlg = new LoginDialog( 0, &port );
    if( pDlg->exec() == QDialog::Accepted) {
        w.showMaximized();
    } else {
        return 0;
    }
    
    return a.exec();
    

    }

    LoginDialog::LoginDialog(QWidget *parent, CurllibPort *pCurl) :
    QDialog(parent),
    ui(new Ui::LoginDialog)
    {
    ui->setupUi(this);
    #define CTL_HEIGHT 30
    #define BTN_WIDTH 60
    QGridLayout *pgLayout = new QGridLayout( this );
    QLabel *pEmailLab = new QLabel( tr("Email:"), this );
    mpUserEmailEdit = new QLineEdit( this );
    mpUserEmailEdit->setFixedHeight( CTL_HEIGHT );
    QLabel *pPassLab = new QLabel( tr("Password:"), this );
    mpPasswordEdit = new QLineEdit( this );
    mpPasswordEdit->setFixedHeight( CTL_HEIGHT );
    mpPasswordEdit->setEchoMode( QLineEdit::Password );
    mpLoginBtn = new QPushButton( tr("Login"), this );
    mpLoginBtn->setFixedSize( BTN_WIDTH, CTL_HEIGHT );
    mpLoginBtn->setDefault( true );

    int nRow = 0;
    pgLayout->addWidget( pEmailLab, nRow, 0 );
    pgLayout->addWidget( mpUserEmailEdit, nRow, 1 );    
    nRow++;
    pgLayout->addWidget( pPassLab, nRow, 0 );
    pgLayout->addWidget( mpPasswordEdit, nRow, 1 );
    nRow++;
    pgLayout->addWidget( mpLoginBtn, nRow, 1 );
       
    this->setLayout( pgLayout );
    mpCurl = pCurl;
    connect( mpLoginBtn, SIGNAL(pressed()), this, SLOT(loginBtnSlot()) );
    

    }
    @

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on last edited by
      #2

      Hi, AFAIK, there is no signal called press() exist in QPushButton.

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zJinWei
        wrote on last edited by
        #3

        I use this statement:
        @
        connect( mpLoginBtn, SIGNAL(clicked()), this, SLOT(loginBtnSlot()) );
        @
        The result is same as using the statement:
        @
        connect( mpLoginBtn, SIGNAL(pressed()), this, SLOT(loginBtnSlot()) );
        @

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Do you have a slot named loginBtnSlot in LoginDialog ?

          Checkout the return value of connect and the console output for potential errors

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            as SGaist said, checking the console output on signal-slot-connection problems (always) gives a well readable hint what went wrong during the connection.

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              zJinWei
              wrote on last edited by
              #6

              The program have a slot named loginBtnSlot in LoginDialog . The console output has no error about the signal-slot-connection problems.
              When I use the statement:
              @
              QMetaObject::Connection conn = connect( mpLoginBtn, SIGNAL(clicked()), this, SLOT(loginBtnSlot()) );
              if( conn ) {
              qDebug() << "conn is ok.";
              }
              @
              It can output "conn is ok.".
              I add these statements below afterwards, then found that everything was all right.
              @
              QPushButton *pCancelBtn = new QPushButton( tr("Cancel"), this );
              connect( pCancelBtn, SIGNAL(clicked()), this, SLOT(reject()) );
              @

              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