views:

63

answers:

1

I have a simple class Networking with a:

private:
    QNetworkAccessManager *httpclient;

I create an object in the constructor and connect signal and slot:

 httpclient = new QNetworkAccessManager(this);
 connect(httpclient, SIGNAL(finished(QNetworkReply*)), this, SLOT(httpRequestFinished(QNetworkReply*)));

Now I am going to call the QNetworkAccessManager's get method via a public method getPage:

void Networking::getPage(const QString &uri)
{
  QNetworkRequest request;
  request.setUrl(uri);
  httpclient->get(request);
}

I expect that httpRequestFinished gets called, but it's not. I also tried it this for testing purposes:

void Networking::getPage(const QString &uri)
{
  QNetworkRequest request;
  request.setUrl(uri);
  reply = httpclient->get(request);
  connect(reply, SIGNAL(finished()), this, SLOT(httpReplyFinished()));
}

where reply is properly defined in file networking.h:

private:
 QNetworkAccessManager *httpclient;
 QNetworkReply *reply;

Nothing changed! But if I access reply->bytesAvailable() after the get-Request all signals are emitted at the same time! I'm searching now for hours but don't know what I am doing wrong.

+1  A: 

so... i found out why - but not exactly: it was memory management. I had to define my object as pointer in my mainwindow class

Networking *nw;

Now i can use it - for example in my pushbutton-action:

nw = new Networking();
nw->getPage("my url here");

All went as expected! Ufff.. Much to learn

tfl