QSslSocket无法解析和权限被拒绝错误

时间:2018-04-25 18:58:00

标签: c++ qt openssl qsslsocket

错误消息如下:

  

qt.network.ssl:QSslSocket:无法解析TLSv1_1_client_method

     

qt.network.ssl:QSslSocket:无法解析TLSv1_2_client_method

     

qt.network.ssl:QSslSocket:无法解析TLSv1_1_server_method

     

qt.network.ssl:QSslSocket:无法解析TLSv1_2_server_method

     

qt.network.ssl:QSslSocket:无法解析SSL_select_next_proto

     

qt.network.ssl:QSslSocket:无法解析SSL_CTX_set_next_proto_select_cb

     

qt.network.ssl:QSslSocket:无法解析SSL_get0_next_proto_negotiated

     

qt.network.ssl:QSslSocket:无法解析SSL_set_alpn_protos

     

qt.network.ssl:QSslSocket:无法解析SSL_CTX_set_alpn_select_cb

     

qt.network.ssl:QSslSocket:无法解析SSL_get0_alpn_selected

我运行Windows 7计算机,在我的D:驱动器上安装了openssl 1.1.0。我正在使用Qt5.9.0

我的.pro文件

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

这是触发错误的代码:

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;

}

我一直收到qt.network.ssl错误,在链接openssl之后我不断收到编译错误:

  

: - 1:错误:找不到D:\ OpenSSL-Win32 \ lib:权限被拒绝

     

: - 1:错误:找不到-llibssl

     

collect2.exe:-1:错误:错误:ld返回1退出状态

即使我目前没有使用OpenSSL,我也愿意稍后再使用它。

1 个答案:

答案 0 :(得分:0)

  1. 仅Qt 5.10支持OpenSSL 1.1.0。请使用OpenSSL 1.0.2l,您可以使用与npcglib编译器匹配的预构建包。

  2. 您的LIBS +=包含是正确的,但似乎您的计算机没有权限或找不到库。无法告知为什么会发生此错误。验证文件夹中是否存在库以及用户是否有权访问。

  3. QNetworkReply *QNetworkAccessManager::get(const QNetworkRequest &request)是一个异步调用。您的函数QString Commands::getPublicIp()可能会在请求完成之前返回一个空的QString。