PDA

View Full Version : Do QWebPage (or other class instance) clear QNetworkReply data?



zygmunt
5th December 2011, 21:26
Hi!

Like in the subject.
I was try two function request and is it possible to clear reply data somewhere in Qt code?
Because when I set test_value to ONLY_NETWORK_REQUEST i get some data in function parseReplay in line 28. But when I load page in webView, function parseReplay is executed, and in line 28 I take emty QByteArray.
Why?



MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

nam = new NetworkAccessManager();
ui->webView->page()->setNetworkAccessManager(nam);

connect(
nam, SIGNAL(finished(QNetworkReply*)),
this, SLOT(parseReply(QNetworkReply*))
);
}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::parseReply(QNetworkReply * r)
{
if( r->isOpen() and r->isFinished() )
{
r->waitForReadyRead(1000);
if( r->reset() )
{
qDebug() << "data: " << r->readAll().size() << r->isReadable();
}
}
}

void MainWindow::on_goButton_clicked()
{
QString url = ui->urlLineEdit->text();
if( ! url.startsWith("http://") )
url.prepend("http://");

switch( test_value )
{
case ONLY_NETWORK_REQUEST:
nam->get(QNetworkRequest(url));
break;

case NETWORK_REQUEST_WITH_WEB_VIEW:
ui->webView->load( url );
break;
}
}