[solved] Qt 5.4 - Proxy settings for QtWebEngine
-
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());
}
@ -
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 -
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 -
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 -
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 -
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 -
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