Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Problem With Opening https related Website
Forum Updated to NodeBB v4.3 + New Features

Problem With Opening https related Website

Scheduled Pinned Locked Moved QML and Qt Quick
11 Posts 4 Posters 8.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tattoo
    wrote on 18 Aug 2011, 07:08 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on 18 Aug 2011, 07:55 last edited by
      #2

      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).

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tattoo
        wrote on 18 Aug 2011, 08:00 last edited by
        #3

        Hello Lukas

        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

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on 18 Aug 2011, 09:50 last edited by
          #4

          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.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tattoo
            wrote on 18 Aug 2011, 10:03 last edited by
            #5

            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&#40;QLatin1String("qml/oauthsample/WebKitExample.qml"&#41;&#41;;
            viewer.showExpanded(&#41;;
            
            return app.exec&#40;&#41;;
            

            }@

            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.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on 18 Aug 2011, 10:29 last edited by
              #6

              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.

              1 Reply Last reply
              0
              • T Offline
                T Offline
                tattoo
                wrote on 18 Aug 2011, 10:34 last edited by
                #7

                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'

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  lgeyer
                  wrote on 18 Aug 2011, 10:36 last edited by
                  #8

                  Add the Q_OBJECT macro and re-run qmake.

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    lgeyer
                    wrote on 18 Aug 2011, 10:38 last edited by
                    #9

                    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).

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      tattoo
                      wrote on 18 Aug 2011, 11:40 last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0
                      • B Offline
                        B Offline
                        blelem
                        wrote on 8 Nov 2011, 20:58 last edited by
                        #11

                        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);
                        }

                        @

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved