[Qt-interest] how to catch response in the fancybrowser example?

Christopher Probst cprobst at ics.com
Mon Mar 22 12:15:22 CET 2010


Hello Meir,

This is probably not the best of solutions, but it does what you want,  
as I suppose that it's for debug purposes.

In webview.cpp around line 197 in constructor of  WebView add

	connect(page()- 
 >networkAccessManager(),SIGNAL(finished(QNetworkReply*)),this,  
SLOT(replyFinished(QNetworkReply*)));

it should look something like this

188  WebView::WebView(QWidget* parent)
189     : QWebView(parent)
190     , m_progress(0)
191     , m_page(new WebPage(this))
192 {
193     setPage(m_page);
194     connect(page(), SIGNAL(statusBarMessage(const QString&)),
195             SLOT(setStatusBarText(const QString&)));
196
197         connect(page()- 
 >networkAccessManager(),SIGNAL(finished(QNetworkReply*)),this,  
SLOT(replyFinished(QNetworkReply*)));
198
199     connect(this, SIGNAL(loadProgress(int)),
200             this, SLOT(setProgress(int)));
201     connect(this, SIGNAL(loadFinished(bool)),
202             this, SLOT(loadFinished()));
203     connect(page(), SIGNAL(loadingUrl(const QUrl&)),
204             this, SIGNAL(urlChanged(const QUrl &)));
205     connect(page(), SIGNAL(downloadRequested(const QNetworkRequest  
&)),
206             this, SLOT(downloadRequested(const QNetworkRequest &)));
207     page()->setForwardUnsupportedContent(true);
208
209 }

Then add the following slot

210 void WebView::replyFinished(QNetworkReply* aReply)
211 {
212 qDebug() << "HTTP Response";
213        if ( aReply )
214        {
215             qDebug() << aReply- 
 >attribute( QNetworkRequest::HttpStatusCodeAttribute );
216
217       }
218 qDebug() << "HTTP Response";


Make sure you add the slot replyFinished(QNetworkReply* aReply)  to  
the header and do a "make clean", "make" (just to be sure that the moc  
file "moc_webview.cpp") is regenerated.
Also add, in this case,  #include <QDebug> to use the "qDebug()  
<<"routine.

The http response in output should be of the form:

			QVariant(int, 200)
			QVariant(int, 400)


Thanks,
Christo











On 22 Mar 2010, at 08:07, Meir Yanovich wrote:

> Hello all
> i like to take the fancybrowser example and catch the response and  
> print it or dump it to file
> no matter what i do using :
> connect(view, SIGNAL(loadFinished(bool)), SLOT(finishLoading(bool)));
> or
> connect(manager, SIGNAL(finished(QNetworkReply*)),this,  
> SLOT(replyFinished(QNetworkReply*)));
> as in the examples and the internet
> i unable to catch the http response
> what im missing here ?
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100322/3d4c88f7/attachment.html 


More information about the Qt-interest-old mailing list