-1

In my Qt5.7 program I have a password security. At some situations I want to ask user for password. I want to do it by separate QDialog. This dialog checks if password are good. And here is a problem. How Can I check from parent Dialog if authorisation was positive?

My dialog:

Sorry for editiong, I haven't transalted it yet

And code to show dialog:

PasswordGet pass;
pass.setWindowFlags(Qt::MSWindowsFixedSizeDialogHint);
pass.setModal(true);
pass.exec();

To sum up, I want to know if user clicks Cancel (dialog just close), or clicks Authorize (password was good, and dialog close)

How can I do this? I don't want to make new global bool and check from parent dialog if bool == 1, it's not secure.

km2442
  • 779
  • 2
  • 11
  • 31
  • Is PasswordGet a subclass of QDialog? – FreddyKay Jun 28 '16 at 12:09
  • 3
    Possible duplicate of [QDialog exec() and getting result value](http://stackoverflow.com/questions/12470806/qdialog-exec-and-getting-result-value) – demonplus Jun 28 '16 at 12:12
  • @demonplus thank you for linking this thread, it helps me with solving my problem. Now my thread could be duplicate :/ – km2442 Jun 29 '16 at 20:36

1 Answers1

1

Don't reinvent the wheel, use the password dialog that Qt already provides. If you need examples of how to use Qt dialogs see their excellent example here: http://doc.qt.io/qt-5/qtwidgets-dialogs-standarddialogs-example.html

You would want to use QDialogEdit::getText with a QLineEdit::EchoMode of QLineEdit::Password. If you're expecting the user to enter: QString password Then your code will look something like this:

bool ok;
QString text = QDialogEdit::getText(this, tr("Authorization"), tr("Password:"), QLineEdit::Password, QString(), &ok);

if(ok && text == password) // Success, do you're action here
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
  • Thank you for idea, but I have solved my issu another way. – km2442 Jun 29 '16 at 20:37
  • 1
    @KamilKlecha If possible you should post your solution here and accept it to benefit anyone coming after you who may also be struggling with the same issue! – Jonathan Mee Jun 29 '16 at 20:38