我正在尝试使用 QNetworkAccessManager
获取URL的源代码...
但似乎信号槽复杂性存在问题!
我的 onFinished(QNetworkReply*)
永远不会被触发!为什么?
void Worker::start(QString url)
{
QNetworkAccessManager manager;
QNetworkReply *reply = manager.get(QNetworkRequest(QUrl(url)));
QObject::connect(reply, SIGNAL(finished(QNetworkReply*)), this, SLOT(onFinished(QNetworkReply*)));
}
void Worker::onFinished(QNetWorkReply * reply)
{
qDebug() << "Slot has been triggered!";
QString html = reply->readAll();
}
编辑:
正如“Oleg Shparber”所述,以下是我的新代码(它也不能工作):
void Worker::start(QString url)
{
QNetworkAccessManager *manager = new QNetworkAccessManager();
QNetworkReply *reply = manager->get(QNetworkRequest(QUrl(url)));
QObject::connect(reply, SIGNAL(finished()), this, SLOT(onFinished()));
void Worker::onFinished()
{
qDebug() << "Slot has been triggered!";
QString html = reply->readAll();
}