Problem With Opening https related Website
-
Hello All,
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).
-
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
{
public:
MyNetworkAccessManagerFactory();
virtual QNetworkAccessManager *create(QObject *parent);public slots:
void ignoreSSLErrors(QNetworkReply* reply,QList<QSslError> errors);private:
QNetworkAccessManager* myManager;};
MyNetworkAccessManagerFactory::MyNetworkAccessManagerFactory()
{
myManager = new QNetworkAccessManager(this);
QObject::connect(myManager,SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)),
this,SLOT(ignoreSSLErrors(QNetworkReply*,QList<QSslError>)));
}QNetworkAccessManager* MyNetworkAccessManagerFactory::create(QObject *parent)
{return myManager;
}
void MyNetworkAccessManagerFactory::ignoreSSLErrors(QNetworkReply* reply,QList<QSslError> errors)
{
reply->ignoreSslErrors(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.
-
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);
QObject::connect(manager,SIGNAL(sslErrors(QNetworkReply,QList<QSslError>)),
this,SLOT(ignoreSSLErrors(QNetworkReply*,QList<QSslError>)));
return manager;
}void SSLSafeNetworkFactory::ignoreSSLErrors(QNetworkReply* reply,QList<QSslError> errors)
{
reply->ignoreSslErrors(errors);
}@