Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void WebPage::authenticationRequired(QNetworkReply* reply, QAuthenticator* authenticator)
- {
- QDialog* dialog = new QDialog(QApplication::activeWindow());
- dialog->setWindowTitle("HTTP Authentication");
- QGridLayout* layout = new QGridLayout(dialog);
- dialog->setLayout(layout);
- QLabel* messageLabel = new QLabel(dialog);
- messageLabel->setWordWrap(true);
- QString messageStr = QString("Enter with username and password for: %1");
- messageLabel->setText(messageStr.arg(reply->url().toString()));
- layout->addWidget(messageLabel, 0, 1);
- #ifndef QT_NO_LINEEDIT
- QLabel* userLabel = new QLabel("Username:", dialog);
- layout->addWidget(userLabel, 1, 0);
- QLineEdit* userInput = new QLineEdit(dialog);
- layout->addWidget(userInput, 1, 1);
- QLabel* passLabel = new QLabel("Password:", dialog);
- layout->addWidget(passLabel, 2, 0);
- QLineEdit* passInput = new QLineEdit(dialog);
- passInput->setEchoMode(QLineEdit::Password);
- layout->addWidget(passInput, 2, 1);
- #endif
- QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
- | QDialogButtonBox::Cancel, Qt::Horizontal, dialog);
- connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
- connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
- layout->addWidget(buttonBox, 3, 1);
- if (dialog->exec() == QDialog::Accepted) {
- #ifndef QT_NO_LINEEDIT
- authenticator->setUser(userInput->text());
- authenticator->setPassword(passInput->text());
- #endif
- }
- delete dialog;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement