[solved] Qt 5.4 - Proxy settings for QtWebEngine
-
wrote on 10 Nov 2014, 09:31 last edited by
Hi,
is there a way to use a proxy with authentication for QtWebEngine module?
It seems NetworkAccessManager is not used...
Greetings
Nando -
wrote on 10 Nov 2014, 10:19 last edited by
Got it:
@
connect(m_webView->page(),
SIGNAL(proxyAuthenticationRequired(const QUrl &, QAuthenticator *, const QString &)),
this, SLOT(proxyAuthenticationRequired(const QUrl &, QAuthenticator *, const QString &)));
@And then in the slot something like this:
@void AirportDisplayer::proxyAuthenticationRequired(const QUrl &, QAuthenticator *auth, const QString &)
{
qDebug() << "AirportDisplayer::proxyAuthenticationRequired:";auth->setUser(FlightbookManager::instance().pilot()->proxyUsername()); auth->setPassword(FlightbookManager::instance().pilot()->proxyPassword());
}
@ -
wrote on 17 Nov 2014, 09:41 last edited by
Thanks for sharing the solution.
-
wrote on 17 Dec 2014, 16:19 last edited by
Can you share how you are setting up the proxy settings (host and port) for the QtWebEngine? My QWebEngineView does not honor the proxy settings made via the QNetworkProxy::setApplicationProxy(proxy) call.
thanks
Paul -
wrote on 17 Dec 2014, 16:19 last edited by
Can you share how you are setting up the proxy settings (host and port) for the QtWebEngine? My QWebEngineView does not honor the proxy settings made via the QNetworkProxy::setApplicationProxy(proxy) call.
thanks
Paul -
wrote on 17 Dec 2014, 17:45 last edited by
Hi Paul.
i do it like this:In my class i have a member of:
@
QNetworkProxy m_networkProxy;
@in constructor of my class i create the QNetworkAccessManager:
@
m_networkAccessManager = new QNetworkAccessManager;
@and the after loading proxy host, port,username and password i set it like this:
@
if (m_proxyEnabled) {
m_networkProxy.setType(QNetworkProxy::HttpProxy);
m_networkProxy.setHostName(m_ProxyHost);
m_networkProxy.setPort(m_ProxyPort);
m_networkProxy.setUser(m_ProxyUsername);
m_networkProxy.setPassword(m_ProxyPassword);
} else {
m_networkProxy.setType(QNetworkProxy::NoProxy);
}// Apply the proxy to the QNetworkAccessManager QNetworkProxy::setApplicationProxy(m_networkProxy); m_pNetworkAccessManager->setProxy(m_networkProxy);
@
Hope that helps ;-)
Greetings
Nando -
wrote on 17 Dec 2014, 17:45 last edited by
Hi Paul.
i do it like this:In my class i have a member of:
@
QNetworkProxy m_networkProxy;
@in constructor of my class i create the QNetworkAccessManager:
@
m_networkAccessManager = new QNetworkAccessManager;
@and the after loading proxy host, port,username and password i set it like this:
@
if (m_proxyEnabled) {
m_networkProxy.setType(QNetworkProxy::HttpProxy);
m_networkProxy.setHostName(m_ProxyHost);
m_networkProxy.setPort(m_ProxyPort);
m_networkProxy.setUser(m_ProxyUsername);
m_networkProxy.setPassword(m_ProxyPassword);
} else {
m_networkProxy.setType(QNetworkProxy::NoProxy);
}// Apply the proxy to the QNetworkAccessManager QNetworkProxy::setApplicationProxy(m_networkProxy); m_pNetworkAccessManager->setProxy(m_networkProxy);
@
Hope that helps ;-)
Greetings
Nando -
wrote on 17 Dec 2014, 19:46 last edited by
Hi Nando
I tried your suggestions but it did not work.
I have the following class and associated methods:@
class LoginWebEngineView : public QWebEngineView
{
Q_OBJECTpublic:
explicit LoginWebEngineView(QWidget *parent = 0, QSettings *settings = 0);
~LoginWebEngineView();
void setProxy();private:
QSettings* m_pSettings;
QNetworkProxy m_networkProxy;
QNetworkAccessManager *m_pNetworkAccessManager;
};LoginWebEngineView::LoginWebEngineView(QWidget *parent, QSettings *settings) :
QWebEngineView(parent)
{
m_pSettings = settings;
m_pNetworkAccessManager = new QNetworkAccessManager;this->setParent(parent); setProxy();
}
void
LoginWebEngineView::setProxy() {
if (m_pSettings->value("proxy_enabled", false).toBool()) {
QString host = m_pSettings->value("proxy_host", "").toString();
quint16 port = m_pSettings->value("proxy_port", 0).toUInt();
QString user = m_pSettings->value("proxy_user", "").toString();
QString password = m_pSettings->value("proxy_pass", "").toString();m_networkProxy.setType(QNetworkProxy::HttpProxy); m_networkProxy.setHostName(host); m_networkProxy.setPort(port); m_networkProxy.setUser(user); m_networkProxy.setPassword(password); } else { m_networkProxy.setType(QNetworkProxy::NoProxy); } // Apply the proxy to the QNetworkAccessManager QNetworkProxy::setApplicationProxy(m_networkProxy); m_pNetworkAccessManager->setProxy(m_networkProxy);
}
@
If you see anything obvious, please let me know.
thanks
Paul -
wrote on 17 Dec 2014, 19:46 last edited by
Hi Nando
I tried your suggestions but it did not work.
I have the following class and associated methods:@
class LoginWebEngineView : public QWebEngineView
{
Q_OBJECTpublic:
explicit LoginWebEngineView(QWidget *parent = 0, QSettings *settings = 0);
~LoginWebEngineView();
void setProxy();private:
QSettings* m_pSettings;
QNetworkProxy m_networkProxy;
QNetworkAccessManager *m_pNetworkAccessManager;
};LoginWebEngineView::LoginWebEngineView(QWidget *parent, QSettings *settings) :
QWebEngineView(parent)
{
m_pSettings = settings;
m_pNetworkAccessManager = new QNetworkAccessManager;this->setParent(parent); setProxy();
}
void
LoginWebEngineView::setProxy() {
if (m_pSettings->value("proxy_enabled", false).toBool()) {
QString host = m_pSettings->value("proxy_host", "").toString();
quint16 port = m_pSettings->value("proxy_port", 0).toUInt();
QString user = m_pSettings->value("proxy_user", "").toString();
QString password = m_pSettings->value("proxy_pass", "").toString();m_networkProxy.setType(QNetworkProxy::HttpProxy); m_networkProxy.setHostName(host); m_networkProxy.setPort(port); m_networkProxy.setUser(user); m_networkProxy.setPassword(password); } else { m_networkProxy.setType(QNetworkProxy::NoProxy); } // Apply the proxy to the QNetworkAccessManager QNetworkProxy::setApplicationProxy(m_networkProxy); m_pNetworkAccessManager->setProxy(m_networkProxy);
}
@
If you see anything obvious, please let me know.
thanks
Paul -
wrote on 17 Dec 2014, 20:05 last edited by
Hi,
i see you have enhirted your class from QWebEngineView.
Try to inherit your class just from QObject and add a member for the
QWebEngineView which gets instantiated before the set proxy stuff:
@
QWebEngineView* m_webEngineView;
@Maybe QWebEngine is looking for proxy settings while creation and there are no proxy stettings at construction time.
Greetings
Nando -
wrote on 17 Dec 2014, 20:05 last edited by
Hi,
i see you have enhirted your class from QWebEngineView.
Try to inherit your class just from QObject and add a member for the
QWebEngineView which gets instantiated before the set proxy stuff:
@
QWebEngineView* m_webEngineView;
@Maybe QWebEngine is looking for proxy settings while creation and there are no proxy stettings at construction time.
Greetings
Nando -
wrote on 17 Dec 2014, 21:12 last edited by
That did not help. My dialog is created in QtCreator, is it possible that this could be part of the issue?
thanks
Paul -
wrote on 17 Dec 2014, 21:12 last edited by
That did not help. My dialog is created in QtCreator, is it possible that this could be part of the issue?
thanks
Paul -
Can you share how you are setting up the proxy settings (host and port) for the QtWebEngine? My QWebEngineView does not honor the proxy settings made via the QNetworkProxy::setApplicationProxy(proxy) call.
thanks
Paul