@Oodini
Seems you want to reinvent the wheel :)
class LoggingDialog: public QDialog
{
Q_OBJECT
public:
LoggingDialog() : QDialog(nullptr)
{
setWindowTitle("Logging");
auto vLayout= new QVBoxLayout(this);
vLayout->setSpacing(14);
combo=new QComboBox;
vLayout->addWidget(combo);
auto label=new QLabel("Enter your password");
vLayout->addWidget(label,0,Qt::AlignCenter);
edit=new QLineEdit;
edit->setTextMargins(2,0,2,0);
edit->setEchoMode(QLineEdit::Password);
vLayout->addWidget(edit);
auto button=new QPushButton("OK");
//button->setEnabled(false);
vLayout->addWidget(button,0,Qt::AlignCenter);
connect(button, &QPushButton::clicked, this,[this]()
{
bool ok=false;
emit checkPassword(currentName(),edit->text(),ok);
if(ok)
{
accept();
}
else
{ // wrong password
QMessageBox msgBox(this);
msgBox.setWindowModality(Qt::WindowModal);
msgBox.setText("Invalid password !");
msgBox.setStandardButtons(QMessageBox::Retry | QMessageBox::Cancel);
if(msgBox.exec()==QMessageBox::Cancel)
reject();
}
});
}
QString currentName()
{
return combo->currentText();
}
signals:
void checkPassword(const QString& name, const QString &pass,bool& ok);
private:
QComboBox* combo;
QLineEdit* edit;
};
...
LoggingDialog dialog;
QObject::connect(&dialog,&LoggingDialog::checkPassword,[](const QString& name, const QString &pass,bool& ok)
{
ok=false; // msgbox will show up
});
if(dialog.exec()==QDialog::Accepted)
{
qDebug()<<"Password correct for"<<dialog.currentName();
}
else
{
qDebug()<<"operation cancelled";
}
[image: Password.png]