diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
index 430fa30a2b10272ffc8882ae3b55b8cd4469d3f2..fd1f548344ac0eb54cc272dc818e33a9a68383af 100644
--- a/src/webenginewidgets/api/qwebenginepage.cpp
+++ b/src/webenginewidgets/api/qwebenginepage.cpp
@@ -33,6 +33,7 @@
 
 #include <QAction>
 #include <QApplication>
+#include <QAuthenticator>
 #include <QClipboard>
 #include <QFileDialog>
 #include <QIcon>
@@ -42,7 +43,6 @@
 #include <QMessageBox>
 #include <QStandardPaths>
 #include <QUrl>
-#include <private/qauthenticator_p.h>
 
 QT_BEGIN_NAMESPACE
 
@@ -313,9 +313,7 @@ void QWebEnginePagePrivate::authenticationRequired(const QUrl &requestUrl, const
 {
     Q_Q(QWebEnginePage);
     QAuthenticator networkAuth;
-    // Detach to trigger the creation of its QAuthenticatorPrivate.
-    networkAuth.detach();
-    QAuthenticatorPrivate::getPrivate(networkAuth)->realm = realm;
+    networkAuth.setRealm(realm);
 
     if (isProxy)
         Q_EMIT q->proxyAuthenticationRequired(requestUrl, &networkAuth, challengingHost);