函数 CheckSite() 使用类似http://example.com的 url 调用,它初始化 QNetworkAccessManager 对象和 connect() 插槽和信号。
manger->get() 调用似乎有效(它会生成 http 流量),但不会在请求结束时调用槽 replyFinished() 。
这段代码有什么问题?
#include <QtCore>
#include <QtNetwork>
class ClientHandler : public QObject
{
Q_OBJECT
QNetworkAccessManager *manager;
private slots:
void replyFinished(QNetworkReply *);
public:
void CheckSite(QString url);
};
void ClientHandler::replyFinished(QNetworkReply *reply) { qDebug() << "DONE"; }
void ClientHandler::CheckSite(QString url) {
QUrl qrl(url);
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
manager->get(QNetworkRequest(qrl));
}