Hi,
I would like to download the source code of a webpage using the QNetworkAccessManager. So I read the documentation (http://doc.trolltech.com/4.6/qnetworkaccessmanager.html) and there's an example:
"...A simple download off the network could be accomplished with:
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
manager->get(QNetworkRequest(QUrl("http://qt.nokia.com")));
When the replyFinished slot above is called, the parameter it takes is the QNetworkReply object containing the downloaded data as well as meta-data (headers, etc.)..."
I wrote the same example, but it looks like that replyFinished is never called. Why ?
Here is my code:
yahooRetriever.cpp
-----------------------------------------------------
#include "yahooRetriever.h"
YahooRetriever::YahooRetriever() {
std::cout << "yahooRetriever" << std::endl;
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(result(QNetworkReply*)));
}
void YahooRetriever::test() {
std::cout << "start test" << std::endl;
manager->get(QNetworkRequest(QUrl("http://www.yahoo.com")));
std::cout << "end test" << std::endl;
}
void YahooRetriever::result(QNetworkReply *reply) {
std::cout << "loading complete" << std::endl;
}
-----------------------------------------------------
main.cpp
-----------------------------------------------------
#include "yahooRetriever.h"
int main(int argc, char *argv[]) {
YahooRetriever yahooRetriever;
yahooRetriever.test();
return 0;
}
-----------------------------------------------------
yahooRetriever.h
-----------------------------------------------------
#include <QtNetwork>
#include <iostream>
class YahooRetriever : QObject {
Q_OBJECT
public:
YahooRetriever();
void test();
private slots:
void result(QNetworkReply *reply);
private:
QNetworkAccessManager *manager;
-----------------------------------------------------
When I run my program, it displays the following:
yahooRetriever
start test
end test
but it should also diplay
loading complete
once the download is complete and it doesn't. It's like the finished signal is never emitted by the manager...
I'm using Qt 4.6 on OS X 10.6 and eclipse to code my project.
Could someone tell me what I do wrong ? I would really appreciate some help![]()
Bookmarks