c++qtopensslqsslsocket

QSslSocket cannot resolve and Permission Denied error


The error messages are the following:

qt.network.ssl: QSslSocket: cannot resolve TLSv1_1_client_method

qt.network.ssl: QSslSocket: cannot resolve TLSv1_2_client_method

qt.network.ssl: QSslSocket: cannot resolve TLSv1_1_server_method

qt.network.ssl: QSslSocket: cannot resolve TLSv1_2_server_method

qt.network.ssl: QSslSocket: cannot resolve SSL_select_next_proto

qt.network.ssl: QSslSocket: cannot resolve SSL_CTX_set_next_proto_select_cb

qt.network.ssl: QSslSocket: cannot resolve SSL_get0_next_proto_negotiated

qt.network.ssl: QSslSocket: cannot resolve SSL_set_alpn_protos

qt.network.ssl: QSslSocket: cannot resolve SSL_CTX_set_alpn_select_cb

qt.network.ssl: QSslSocket: cannot resolve SSL_get0_alpn_selected

I run a Windows 7 machine, with openssl 1.1.0 installed on my D: drive. And I am using Qt5.9.0

My .pro file

QT += core network
QT -= gui

CONFIG += c++11 console
CONFIG -= app_bundle

# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += main.cpp \
    server.cpp \
    commands.cpp \
    packet.cpp

HEADERS += \
    server.h \
    commands.h \
    packet.h

INCLUDEPATH += D:\OpenSSL-Win32\include\openssl
INCLUDEPATH += D:\OpenSSL-Win32\bin
LIBS += -L D:\OpenSSL-Win32\lib -llibcrypto
LIBS += -L D:\OpenSSL-Win32\lib -llibssl

And this is the code that triggers the error:

QString Commands::getPublicIp()
{

    QString temp;

    QNetworkAccessManager networkManager;
    QUrl url("http://api.ipify.org");

    QString query = "format=json";

    url.setQuery(query);

    QNetworkReply* reply = networkManager.get(QNetworkRequest(url));

    QObject::connect(
                reply
                , &QNetworkReply::finished
                , [&](){

                        if(reply->error() != QNetworkReply::NoError) {
                            return QString();
                        } else {
                                QJsonObject jsonObject= QJsonDocument::fromJson(reply->readAll()).object();
                                QHostAddress ip(jsonObject["ip"].toString());

                                temp = QString("002 " + ip.toString());
                        }

                reply->deleteLater();
                }
            );

    return temp;

}

I kept getting the qt.network.ssl errors, and after linking openssl I keep getting a compile error:

:-1: error: cannot find D:\OpenSSL-Win32\lib: Permission denied

:-1: error: cannot find -llibssl

collect2.exe:-1: error: error: ld returned 1 exit status

Even though I am not currently using OpenSSL, I am willing to use it later.


Solution

    1. OpenSSL 1.1.0 is only supported from Qt 5.10. Please use OpenSSL 1.0.2l, you can use the pre-built package that matches your compiler from npcglib.

    2. Your LIBS += includes are correct, but it appears your compute has no permission or the libraries are not found. It cannot be told why this error occurs. Verify the existence of the libraries in the folder and that your user has access.

    3. QNetworkReply *QNetworkAccessManager::get(const QNetworkRequest &request)is an asynchron call. Your function QString Commands::getPublicIp() will probably return an empty QString before the request has finished.