我有以下代码,使用QNetworkAccessManager获取URL的响应,并使用QNetworkReply获取响应代码。在Windows 8中进行测试时,我正确地获得了onReplyfinished()插槽。在Windows 10中使用该应用程序时,没有得到onReplyfinished()。
NetManager.h :
class NetManager:public QNetworkAccessManager
{
Q_OBJECT
public:
NetManager(QObject* inParent = 0);
~NetManager();
public slots:
void onReplyfinished();
private:
QNetworkAccessManager *AManager;
QNetworkReply *NReply;
QString urlStr;
};
NetManager.cpp :
NetManager::NetManager( QObject* inParent ) : QNetworkAccessManager(
inParent )
{
AManager = new QNetworkAccessManager(this);
urlStr= "https://sampleurl.com/";
qDebug() << urlStr;
QUrl url(urlStr);
QNetworkRequest NetRequest((url));
NReply= AManager->get(NetRequest);
connect(NReply, SIGNAL(finished()), this, SLOT(onReplyfinished()));
}
void NetManager::onReplyfinished()
{
qDebug () << "in getting response";
}
预先感谢
答案 0 :(得分:0)
不要忘记添加
{.1文件中的QT += network
如果您遇到ssl问题,请不要忘记将libcrypto
和libssl
复制到您的项目目录中