PDA

View Full Version : QNetworkAccessManager question



_Stefan
3rd March 2010, 13:59
Hello,

I am trying to make a HTTP get request, to a script that has a loop in it and posts data back at certain times.
For testing, in example, we made a little script, that returns some XML, as in, it gives use the XML header first, and every second after that, it will return a XML tag with some information we like. It does this 5 times, so it takes 5 seconds for the script to end, in this case.

For the real thing, the script will not end, or will be active for a longer period of time the least.

The problem is, when I use QNetworkAccessManager, it works fine doing the request and in the finished slot, I get my request data.
However, what it does, is, it waits the 5 seconds for the whole script to be executed. What I want is, that it first gives me some data, and then, every time some event when there is more data.

In fact, I would like to receive up to the XML header, and every time there is that delay of a second, a new event I have received data.

I guess it would be like a motion JPEG thing, where one would keep receiving the new JPEG data, just now, I want to receive XML tags.

I cannot find any setting, to get this to work, other than that I need to wait for the script to actually end.
The script works in Firefox, because it adds the XML tags every second until they are all there.

I hope I make any sense. Can anyone help me on this?

_Stefan
5th March 2010, 12:21
No one?

This is the little test code i got, to clarify a bit more:



m_httpMan = new QNetworkAccessManager(this);

void MainWindow::on_btnURL_clicked()
{
QNetworkRequest request(QUrl(ui->txtURL->text()));

m_httpReply = m_httpMan->get(request);

connect (m_httpReply, SIGNAL(readyRead()), this, SLOT(on_httpReplyReadyRead()));
connect (m_httpReply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(on_downloadProgress(qint64,qint64)));
}


void MainWindow::on_httpReplyReadyRead()
{
QByteArray newData = m_httpReply->read(2048);
ui->txtReply->appendPlainText("ReadyRead:");
ui->txtReply->appendPlainText(newData);
}


It's a form with a URL input box. After clicking the btnURL button, I make the request.
I expected the readyRead signal to be triggered every time I receive some data. Instead, it waits till the whole script has finished and then triggers it with the full data.

Is there a workaround, so readyRead get's triggered with chunks of data, ie. after an end of line or something?

Thanks in advance