Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. void WebPage::authenticationRequired(QNetworkReply* reply, QAuthenticator* authenticator)
  2. {
  3. QDialog* dialog = new QDialog(QApplication::activeWindow());
  4. dialog->setWindowTitle("HTTP Authentication");
  5.  
  6. QGridLayout* layout = new QGridLayout(dialog);
  7. dialog->setLayout(layout);
  8.  
  9. QLabel* messageLabel = new QLabel(dialog);
  10. messageLabel->setWordWrap(true);
  11. QString messageStr = QString("Enter with username and password for: %1");
  12. messageLabel->setText(messageStr.arg(reply->url().toString()));
  13. layout->addWidget(messageLabel, 0, 1);
  14.  
  15. #ifndef QT_NO_LINEEDIT
  16. QLabel* userLabel = new QLabel("Username:", dialog);
  17. layout->addWidget(userLabel, 1, 0);
  18. QLineEdit* userInput = new QLineEdit(dialog);
  19. layout->addWidget(userInput, 1, 1);
  20.  
  21. QLabel* passLabel = new QLabel("Password:", dialog);
  22. layout->addWidget(passLabel, 2, 0);
  23. QLineEdit* passInput = new QLineEdit(dialog);
  24. passInput->setEchoMode(QLineEdit::Password);
  25. layout->addWidget(passInput, 2, 1);
  26. #endif
  27.  
  28. QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
  29. | QDialogButtonBox::Cancel, Qt::Horizontal, dialog);
  30. connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
  31. connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
  32. layout->addWidget(buttonBox, 3, 1);
  33.  
  34. if (dialog->exec() == QDialog::Accepted) {
  35. #ifndef QT_NO_LINEEDIT
  36. authenticator->setUser(userInput->text());
  37. authenticator->setPassword(passInput->text());
  38. #endif
  39. }
  40.  
  41. delete dialog;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement