我有一个非常奇怪的问题我创建了一个应用程序,使用 QNetworkAcessManager 下载 HTML 页面并从此页面获取数据我发布了我的应用程序以在同一无线连接上的第二台笔记本电脑上使用它,但它不起作用。< br/> 在我的计算机上,发布应用程序并使用windeploy.exe获取此版本exe的所有dll文件后,我尝试在我的计算机上使用它,该计算机具有QT并在其上开发,它工作正常并获取文件中的数据。< br/> 当我在另一台计算机上使用它时,问题就出现了,应用程序可以工作,但是当我按下按钮获取数据时,它什么也得不到,只是空文件 所以这个问题有什么帮助吗 这是我使用普通 QNetworkAcessManager 代码来获取 HTML 页面数据的代码 按钮中的此代码用于获取数据
manager->clearAccessCache();
manager->clearConnectionCache();
if (reply != nullptr)
delete reply;
reply = manager->get(QNetworkRequest(QUrl("https://normalpage.html")));
connect(reply, SIGNAL(readyRead()), this, SLOT(readyRead()));
connect(reply, SIGNAL(finished()), this, SLOT(Finish()));
已读
void MainWindow::readyRead()
{
data.append(reply->readAll());
}
finish函数我获取QByteArray类型的数据并使用它从中获取数据该函数很长
我遇到这个问题大约两个月了,但我很着急,所以我使用 libcurl 和 QProcess 来获取此 HTML 页面数据,但我现在想知道是什么原因导致了这个问题
更新
我使用 main.cpp 中的代码来获取文件中的所有 Qt 警告和错误,如 Macias 的评论中提到的那样,并将其放入我使用的附加到文件的文件中,这样我就可以获得它出现的所有错误,我从 QSslSocket 收到一些警告,如果有人可以检查这些警告并看看它是否导致问题,因为我不知道
错误文件
Warning: QSslSocket: cannot call unresolved function ERR_get_error ((null):0, (null))
)
))
Warning: QSslSocket: cannot call unresolved function SSLv23_client_method ((null):0, (null))
Warning: QSslSocket: cannot call unresolved function SSL_CTX_new ((null):0, (null))
Warning: QSslSocket: cannot call unresolved function SSL_library_init ((null):0, (null))
Warning: QSslSocket: cannot call unresolved function ERR_get_error ((null):0, (null))
Warning: QSslSocket: cannot call unresolved function ERR_get_error ((null):0, (null))
Warning: QSslSocket: cannot call unresolved function SSLv23_client_method ((null):0, (null))
Warning: QSslSocket: cannot call unresolved function SSL_CTX_new ((null):0, (null))
Warning: QSslSocket: cannot call unresolved function SSL_library_init ((null):0, (null))
Warning: QSslSocket: cannot call unresolved function ERR_get_error ((null):0, (null))
Warning: QSslSocket: cannot call unresolved function ERR_get_error ((null):0, (null))
但是在工作计算机中我收到了这个警告
Warning: QSslSocket: cannot resolve SSL_set_alpn_protos ((null):0, (null))
Warning: QSslSocket: cannot resolve SSL_CTX_set_alpn_select_cb ((null):0, (null))
Warning: QSslSocket: cannot resolve SSL_get0_alpn_selected ((null):0, (null))
Warning: QSslSocket: cannot resolve SSL_set_alpn_protos ((null):0, (null))
Warning: QSslSocket: cannot resolve SSL_CTX_set_alpn_select_cb ((null):0, (null))
Warning: QSslSocket: cannot resolve SSL_get0_alpn_selected ((null):0, (null))
更新
当我在可执行文件文件夹中添加新的 dll 文件时,它会给我这个警告
Warning: QSslSocket: cannot call unresolved function SSLv23_client_method ((null):0, (null))
Warning: QSslSocket: cannot call unresolved function SSL_CTX_new ((null):0, (null))
Warning: QSslSocket: cannot call unresolved function SSL_library_init ((null):0, (null))
Warning: QSslSocket: cannot call unresolved function ERR_get_error ((null):0, (null))
Warning: QSslSocket: cannot call unresolved function ERR_get_error ((null):0, (null))
将回复连接到错误信号
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(Error(QNetworkReply::NetworkError)));
插槽就在这里
void MainWindow::Error(QNetworkReply::NetworkError Myerror)
{
qDebug() << "QNetworkReply::NetworkError = " << Myerror;
}
这是我在连接错误信号和属性后得到的
Warning: QSslSocket: cannot call unresolved function SSLv23_client_method ((null):0, (null))
Warning: QSslSocket: cannot call unresolved function SSL_CTX_new ((null):0, (null))
Warning: QSslSocket: cannot call unresolved function SSL_library_init ((null):0, (null))
Warning: QSslSocket: cannot call unresolved function ERR_get_error ((null):0, (null))
Warning: QSslSocket: cannot call unresolved function ERR_get_error ((null):0, (null))
Debug: QNetworkReply::NetworkError = QNetworkReply::NetworkError(UnknownNetworkError) ((null):0, (null))
Debug: Attribute in finish slot = QVariant(Invalid) ((null):0, (null))
当我将这三个 dll 文件添加到我的计算机上的发布文件夹时,我的应用程序在没有它们的情况下工作,我收到此错误
当我转到 C:\AppServ\Apache24\bin 的路径并从该文件夹复制此 dll(libeay32.dll 和 ssleay32.dll)而不是我从 dll 网站下载的其他文件时,它终于可以工作了,但是appchace文件夹中的和从网站下载的有什么区别?
提前致谢
最佳答案
确保您的部署文件夹中有 libeay32.dll
、libssl32.dll
和 ssleay32.dll
库。如果不是,只需将它们复制到 *.exe 旁边
windeployqt
工具不包含这些库。
编辑:
您的错误可能是由不兼容的 openSSL 库版本引起的。
编译时使用的版本与运行时使用的版本不同。您可以轻松查看。在 main.cpp
中创建 QApplication
之后添加以下行:
qDebug() << "SslSupport: " << QSslSocket::supportsSsl();
qDebug() << "SslLibraryBuildVersion: " << QSslSocket::sslLibraryBuildVersionString();
qDebug() << "SslLibraryRuntimeVersion: " << QSslSocket::sslLibraryVersionString();
您应该安装与构建版本最相似的版本并将其放入您的版本中。
关于qt - QNetworkAcessManager 在不同计算机上无法在 Release模式下工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46103035/