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. Switch to another Form
Forum Updated to NodeBB v4.3 + New Features

Switch to another Form

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 3 Posters 4.0k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #6

    Thanks. I take a look at QDialog

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #7

      I have a Problem with my QDialog. When i click Ok in my QDialog and i check the password, the QDialog always sets the QDialog as accepted. It doesnt matter if the Password is correct or wrong. I normally use a clicked Slot to perform some Actions and if the Password doesnt match, show a QMessageBox. But the MessageBox shows, if the password is wrong, and the QDialog sets automatically accepted.

      I need a disconnect Signal to prevent QDialog to Close automatically after clicking Ok. How can i do this?

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by Chris Kawa
        #8

        @Fuel said:

        I need a disconnect Signal to prevent QDialog to Close automatically after clicking Ok. How can i do this?

        That would be working around a built-in mechanism of the designer (I assume your dialog has a QDialogButtonBox and is connected automatically by the uic). The intended way of doing this is overriding the accept slot and doing your logic there. Something along the lines of this:

        void YourDialog::accept()
        {
            if ( /* password is correct */)
                QDialog::accept(); 
            else
                QMessageBox::warning(this, tr("Login failed"), tr("Bummer. The password is incorrect :("), QMessageBox::Ok);
        }
        
        1 Reply Last reply
        1
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #9

          Ok that works. but my Dialog closes after he shows the QMessageBox and the User isnt available to re-enter the Password.

          1 Reply Last reply
          0
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by
            #10

            That shouldn't happen as the "closing code" is only in QDialog::accept. Can you show your actual code? Connections, button setup etc.

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by A Former User
              #11

              this is my method if the button ok is pressed. edit: uhmm thats the dialog before my other one shows. its set a password on first start. but it closes.

              void PasswordDialog::acceptedSlot()
              {
                  if (ui->lePassword->text() == ui->lePasswordVal->text() && ui->lePassword->text() != "" &&
                          ui->lePasswordVal->text() != "")
                  {
                      QByteArray pwd;
                      QString hashedPwd;
                      GDatabase db;
                      QFile file("ep.bin");
              
                      pwd.append(ui->lePassword->text());
                      hashedPwd = QString(QCryptographicHash::hash(pwd, QCryptographicHash::Sha3_512).toHex());
                      db.insertPassword(hashedPwd);
                      file.open(QIODevice::WriteOnly);
                      QDataStream stream(&file);
                      stream << hashedPwd;
                      file.close();
                      this->accept();
                  }
                  else
                  {
                      QMessageBox msgBox;
                      msgBox.setText("Die Passwörter stimmen nicht überein. Bitte die Eingabe überprüfen.");
                      msgBox.exec();
                  }
              }
              
              1 Reply Last reply
              0
              • Chris KawaC Offline
                Chris KawaC Offline
                Chris Kawa
                Lifetime Qt Champion
                wrote on last edited by Chris Kawa
                #12

                Well you didn't do what I said. I said you should override the accept slot, not create your own.

                If you're using the QDialogButtonBox the designer wizard adds by default then it doesn't matter what you do in your own slot. The generated code connects button box signals to the accept/reject slot, so if you call accept in your own slot it will just be called twice. If not then it will be called anyway.

                Move that code to the overriden accept slot, change this->accept() to QDialog::accept() and it will work like you want it to.

                Btw. Don't do that: ui->lePassword->text() != "". QString has a dedicated and faster method for checking if a string is empty - the isEmpty() method.

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #13

                  ok thx. but how do i close the dialog now without calling accept? that would be an loop. the rest works. thx for the tipp

                  1 Reply Last reply
                  0
                  • Chris KawaC Offline
                    Chris KawaC Offline
                    Chris Kawa
                    Lifetime Qt Champion
                    wrote on last edited by
                    #14

                    how do i close the dialog now without calling accept?

                    You do call accept. The base implementation. this->accept() would call your own implementation and it would indeed be recursive, but I said you should call QDialog::accept(), which is the base implementation, not your override. This will close the dialog.

                    1 Reply Last reply
                    0
                    • ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #15

                      Ahhhhh i got it. Thank you very much. Im happy that there are people like you. It works now and i have something i can work with. have a nice weekend.

                      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