Skip to content

Instantly share code, notes, and snippets.

@gokmen
Created April 30, 2012 14:16
Show Gist options
  • Save gokmen/2558692 to your computer and use it in GitHub Desktop.
Save gokmen/2558692 to your computer and use it in GitHub Desktop.
If you have trouble with QWebView and SSL errors you can ignore SSL errors to render page correctly.
#include <QDebug>
#include <QWidget>
#include <QNetworkReply>
#include <QSslConfiguration>
App::App(QWidget *parent) :
QWidget(parent),
ui(new Ui::App)
{
ui->setupUi(this);
QSslConfiguration sslCfg = QSslConfiguration::defaultConfiguration();
QList<QSslCertificate> ca_list = sslCfg.caCertificates();
QList<QSslCertificate> ca_new = QSslCertificate::fromData("CaCertificates");
ca_list += ca_new;
sslCfg.setCaCertificates(ca_list);
sslCfg.setProtocol(QSsl::AnyProtocol);
QSslConfiguration::setDefaultConfiguration(sslCfg);
connect(ui->webView->page()->networkAccessManager(),
SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError> & )),
this,
SLOT(sslErrorHandler(QNetworkReply*, const QList<QSslError> & )));
}
void App::sslErrorHandler(QNetworkReply* qnr, const QList<QSslError> & errlist)
{
#if DEBUG_ENABLED
qDebug() << "---frmBuyIt::sslErrorHandler: ";
// show list of all ssl errors
foreach (QSslError err, errlist)
qDebug() << "ssl error: " << err;
#endif
qnr->ignoreSslErrors();
}
@cyc0der
Copy link

cyc0der commented Jul 23, 2015

is it works for some website like google.com ? ( they're force to use HTTPS )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment