Hey,
I'm trying to make an application that is designed to grab data from a website in a thread but for some reason, despite having no errors in compile/run, the slot never seems to get fired.
Heres my code:
void itemthread::run() {
int i;
for(i=1; i < 10; i++) {
out << i;
QNetworkAccessManager *manager = new QNetworkAccessManager();
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(gotData(QNetworkReply *)));
QNetworkRequest request;
request.setUrl(url);
request.setRawHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
manager->get(request);
}
}
void itemthread::run() {
int i;
QTextStream out(stdout, QIODevice::WriteOnly);
for(i=1; i < 10; i++) {
out << i;
QNetworkAccessManager *manager = new QNetworkAccessManager();
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(gotData(QNetworkReply *)));
QString url_string = QString("http://www.someurl.com?arg=%1").arg(i);
QUrl url(url_string);
QNetworkRequest request;
request.setUrl(url);
request.setRawHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
manager->get(request);
}
}
To copy to clipboard, switch view to plain text mode
"itemthread" is a class that extends QThread. My slot "gotData" never seems to be fired, no matter how long you leave the program running. I had to remove this from new QNetworkAccessManager because it was causing a error during runtime ("QObject: Cannot create children for a parent that is in a different thread.").
How can I request URLs while inside a QThread?
Thanks,
Tom
Bookmarks