Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Problem With Opening https related Website
I have a problem which is only with respect to Nokia N8 devices, Where i am using a QML Webview component for getting authenticated with a social network site.
But in my N8 QML webview it always fires the signal onLoadFailed.
Anybody have clues why this is happening.
This might be caused by a missing or invalid certificate on the N8 which causes a SSL error. Provide your own QNAM to the declarative engine which ignores or fixes SSL errors (see "QDeclarativeNetworkAccessManagerFactory":http://doc.qt.nokia.com/latest/qdeclarativenetworkaccessmanagerfactory.html).
thanks a lot for your answer.
I am not a Qt Expert so can you give me some example on how i can do that.
or some pointers where i can start with.
Thanks a lot
The QML engine uses "QNetworkAccessManager":http://doc.qt.nokia.com/latest/qnetworkaccessmanager.html for all network access. If "the SSL/TLS session encountered errors during the set up, including certificate verification errors" QNetworkAccessManager emits the signal "sslErrors":http://doc.qt.nokia.com/latest/qnetworkaccessmanager.html#sslErrors. The slot connected to this signal may decide to "ignore the SSL error":http://doc.qt.nokia.com/latest/qnetworkreply.html#ignoreSslErrors and process on.
The QML engine uses a "QDeclarativeNetworkAccessManagerFactory":http://doc.qt.nokia.com/latest/qdeclarativenetworkaccessmanagerfactory.html to create a QNetworkAccessManager "on demand":http://doc.qt.nokia.com/latest/qdeclarativeengine.html#setNetworkAccessManagerFactory. By implementing your own QDeclarativeNetworkAccessManagerFactory subclass you can provide your own caching, proxy, cookie or SSL error handling implementation.
It basically boils down to
- Create a QDeclarativeNetworkAccessManagerFactory subclass and reimplement the "create":http://doc.qt.nokia.com/latest/qdeclarativenetworkaccessmanagerfactory.html#create method, which returns a QNetworkAccessManager which -ignores- handles certificate validation errors (using the sslErrors signal).
- Set the QDeclarativeNetworkAccessManagerFactory subclass as the factory for your declarative engine using "setNetworkAccessManagerFactory":http://doc.qt.nokia.com/latest/qdeclarativeengine.html#setNetworkAccessManagerFactory.
Make sure you have read the "QDeclarativeNetworkAccessManagerFactory details ":http://doc.qt.nokia.com/latest/qdeclarativenetworkaccessmanagerfactory.html#details and see the "example":http://doc.qt.nokia.com/latest/declarative-cppextensions-networkaccessmanagerfactory.html.
bq. Note that calling ["ignoreSslErrors()":http://doc.qt.nokia.com/latest/qnetworkreply.html#ignoreSslErrors] without restraint may pose a security risk for your application. Use it with care.
ok while waiting for your reply i digged through some documents and links then i tried something like below in my main.cpp:
@class MyNetworkAccessManagerFactory : public QObject, public QDeclarativeNetworkAccessManagerFactory
virtual QNetworkAccessManager *create(QObject *parent);
void ignoreSSLErrors(QNetworkReply* reply,QList<QSslError> errors);
myManager = new QNetworkAccessManager(this);
QNetworkAccessManager* MyNetworkAccessManagerFactory::create(QObject *parent)
void MyNetworkAccessManagerFactory::ignoreSSLErrors(QNetworkReply* reply,QList<QSslError> errors)
int main(int argc, char *argv)
QApplication app(argc, argv);
QmlApplicationViewer viewer; MyNetworkAccessManagerFactory* myNetworkAccessManagerFactory = new MyNetworkAccessManagerFactory(); viewer.engine()->setNetworkAccessManagerFactory(myNetworkAccessManagerFactory); viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto); viewer.setMainQmlFile(QLatin1String("qml/oauthsample/WebKitExample.qml")); viewer.showExpanded(); return app.exec();
But while running i get an error like :
Object::connect: No such slot QObject::ignoreSSLErrors(QNetworkReply*,QList<QSslError>)
Now i already have a slot but why i am getting this error i dont know any help on this will be greatful.
andre last edited by
Seems clear to me. The slot you are trying to connect to, does not exist.
And, that is correct, because you forgot the Q_OBJECT macro in your class declaration. Add it, re-run qmake and recompile.
ok i had done that but that time i used to get a compile time error like
bq. error: undefined reference to `vtable for MyNetworkAccessManagerFactory'
Add the Q_OBJECT macro and re-run qmake.
In addition, I'm not quite sure if it is valid to return the same QNetworkAccessManager object from subsequent calls to create() (the example does not).
thanks guys , i just took away the class from main.cpp into a separate header and cpp file and issue was solved.
now i am able to load webviews with https.
blelem last edited by
I faced same problem when trying to connect to facebook "https://facebook.com/..." with my app running in Windows. Same app worked just fine on my Mac.
The solution above worked nicely until I added an image item in my QML. I then started to get run-time warnings "qobject cannot create children for a parent that is in a different thread". Besides the warning, the code still ran fine, but that's a scary warning, and I tried to get rid of it. This variation that returns a different NetworkAccessManager everytime a create() is requested, basically a copy of the "example":http://doc.qt.nokia.com/latest/declarative-cppextensions-networkaccessmanagerfactory.htmlexample [doc.qt.nokia.com]), worked for me.
"SSLSafeNetworkFactory::SSLSafeNetworkFactory() : QDeclarativeNetworkAccessManagerFactory()
QNetworkAccessManager* SSLSafeNetworkFactory::create(QObject parent)
QNetworkAccessManager * manager = new QNetworkAccessManager(parent);
void SSLSafeNetworkFactory::ignoreSSLErrors(QNetworkReply* reply,QList<QSslError> errors)