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



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

    }
    @



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



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


  • Lifetime Qt Champion

    Do you have a slot named loginBtnSlot in LoginDialog ?

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


  • Moderators

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



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


Log in to reply
 

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