Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    4
    6
    1489
    Loading More Posts
    • 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
      zJinWei last edited by

      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 Reply Quote 0
      • D
        dbzhang800 last edited by

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

        1 Reply Last reply Reply Quote 0
        • Z
          zJinWei last edited by

          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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • raven-worx
              raven-worx Moderators last edited by

              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 Reply Quote 0
              • Z
                zJinWei last edited by

                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 Reply Quote 0
                • First post
                  Last post