HTTPS via Qt QWebView not working in all cases
I started this on the general forum but decided to add it here as well because this seems to be the more appropriate venue.
More details about the problem can be found on that thread..
http://developer.qt.nokia.com/forums/viewthread/5775/
Thinking that maybe it was code in my existing project causing the problem, I created a brand new project. The project only has the main window that contains a QWebView widget. Project was created using Qt Creator 2.2.
- #-------------------------------------------------
- #
- # Project created by QtCreator 2011-05-11T07:33:27
- #
- #-------------------------------------------------
- QT += core gui
- QT += webkit
- TARGET = TestStuff
- TEMPLATE = app
- SOURCES += main.cpp\
- MainWindow.cpp
- HEADERS += MainWindow.h
- FORMS += MainWindow.ui
This is painfully simple. Just executing one line of code…the “ui->webView->load”.
- #include "MainWindow.h"
- #include "ui_MainWindow.h"
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- //**this line loads a simple html file and displays it. Doing a "form POST" from within the loaded html to a secure https website does not work.
- //ui->webView->load( QUrl::fromLocalFile(QApplication::applicationDirPath() + "/" + "Help" + "/" + "h-2BuyButton-SFA.html") );
- //**this line works fine. The qt.gitorious.org https website opens and displays in the webview
- //ui->webView->load(QUrl("https://qt.gitorious.org/"));
- //**this line does not work. Actual url elided. Nothing is loaded or displayed in the webview
- .
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
I can open the simple html file with Internet Explorer and it will display. When I click a “buy” button, my secure https website opens at the order entry page.
I can open Internet Explorer and paste the “https://qt.gitorious.org/” url into the navigate to bar and visit the Qt https website.
I can open Internet Explorer and paste the “https://mysecure.gateway.com/really.secure” url into the the navigate to bar and visit my https order processing website.
So what is preventing the webview from visiting my https order processing website?
Why does loading one https website work, but not the other?
I also tried the complete project(not the downsized project shown above) on a Mac with the same results.
Is this a bug that needs to be reported?
7 replies
Evidently this problem has been around for a while. Found a thread on the Qt Centre forum from 2009 that was experiencing something similar. Was able to tweak code as follows…
In my “form” instantiation, I connected the qwebview’s qnam to the appropriate signal and slot before loading the https url into the webview…
- connect(ui->webView->page()->networkAccessManager(),
- this,
In the .h
In the .cpp
- {
- #if DEBUG_BUYIT
- qDebug() << "---frmBuyIt::sslErrorHandler: ";
- // show list of all ssl errors
- qDebug() << "ssl error: " << err;
- #endif
- qnr->ignoreSslErrors();
- }
The ssl errors happen and are ignored…which allows my https webpage to load.
What I tried: with the same communication code (based on QNetworkAccessManager) https://twitter.com can be reqested and it doesn’t emit the sslErrors(…) signal. But it does for our site.
The site’s certificate is accepted by Google Chrome, Internet Explorer, Opera, Firefox, … But QNetworkAccessManager emits sslErrors(…) with these QSslErrors:
- BaseNetworkRequest::_sslErrors : Error: "The issuer certificate of a locally looked up certificate could not be found"
- BaseNetworkRequest::_sslErrors : Error: "The root CA certificate is not trusted for this purpose"
- BaseNetworkRequest::_sslErrors : Error: "No certificates could be verified"
I tried to manually add the cert to the request, but it still emits these SslErrors.
- DLog("Cert: ") << certContent;
- DLog("Is cert valid: ") << cert.isValid();
- DLog("Cert info: ") << cert.effectiveDate() << cert.expiryDate() << cert.issuerInfo(QSslCertificate::Organization);
- caCerts.append(cert);
- sslConfig.setCaCertificates(caCerts);
- networkRequest->setSslConfiguration(sslConfig);
cert.isValid() return true, and I can get the effectiveDate and the other certificate information and are all correct.
Am I missing something? I Googled a lot and the only solution I found is to call the QNetworkReply’s ignoreSslErrors() method, which works, but I don’t want to use it if I not have to.
Has this been submitted as a bug to QT?
We are getting this within our project as well but can’t determine if it’s an issue on our side or if the site we’re connecting to has an invalid certificate. Connecting to them via firefox seems to work fine 9 times out of 10 (where the tenth time firefox shows a “untrusted certificate” error).
You must log in to post a reply. Not a member yet? Register here!


