How to add HTTPS support to QNetworkAccessManager ?



  • How do i add HTTPS/ssl support to the following code so it can work with HTTPS links ?

    Currently getting problem :
    QSslSocket: cannot call unresolved function SSL_CTX_new
    QSslSocket: cannot call unresolved function SSL_library_init
    QSslSocket: cannot call unresolved function ERR_get_error

    class MyClass : public QObject
    {
     Q_OBJECT
    public:
        MyClass();
        void fetch();
    
    public slots:
        void replyFinished(QNetworkReply*);
    
    private:
        QNetworkAccessManager* m_manager;
    };
    
    
    MyClass::MyClass()
    {
        m_manager = new QNetworkAccessManager(this);
    
        connect(m_manager, SIGNAL(finished(QNetworkReply*)),
             this, SLOT(replyFinished(QNetworkReply*)));
    
    }
    
    void MyClass::fetch()
    {
        m_manager->get(QNetworkRequest(QUrl("http://stackoverflow.com")));
    }
    
    void MyClass::replyFinished(QNetworkReply* pReply)
    {
    
        QByteArray data=pReply->readAll();
        QString str(data);
    
        //process str any way you like!
    
    }
    

    Full source: https://www.dropbox.com/s/9gkycyliz0h6cyp/netreader.zip?dl=0


  • Lifetime Qt Champion

    Hi,

    Do you have OpenSSL installed on your system ?

    Which OS are you using by the way ?



  • @SGaist using windows i've compiled qt from source with ssl support, yes i have OpenSSL installed + i have a compiled one under C:/deps/ and i added the following to .pro :

    OPENSSL_INCLUDE_PATH=C:/deps/openssl-1.0.1l/include
    OPENSSL_LIB_PATH=C:/deps/openssl-1.0.1l

    win32:QMAKE_LFLAGS *= -Wl,--dynamicbase -Wl,--nxcompat -static
    win32:QMAKE_LFLAGS += -static-libgcc -static-libstdc++

    INCLUDEPATH += $$OPENSSL_INCLUDE_PATH
    LIBS += $$join(OPENSSL_LIB_PATH,,-L,)

    windows:LIBS += -lws2_32 -lshlwapi -lmswsock -lole32 -loleaut32 -luuid -lgdi32


  • Lifetime Qt Champion

    If you are running Qt Creator, go to the Run part of the Project panel and check whether the path to OpenSSL's DLLs can be found in the PATH environment variable. If not, add it there (don't do it system wide)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.