PDA

View Full Version : Can't get webpage to open using 'QHttp'



rishiraj
29th January 2009, 11:07
Hi,
I tried to implement the 'QHttp' example given in the Qt documents.
What I want is that when I click "openTrolltech",the Trolltech webpage should open up.

The code I am using is a slightly cropped version of the one given in the docs--


void ImageViewer::openurl()
{
QHttp *http=new QHttp(this);
http->setHost("www.trolltech.com");
http->get(QUrl::toPercentEncoding("/index.html"));

}


It's not showing any error but the page/Browser isn't opening up.
I added QT+=network in the .pro file and added the proper header files.
What's wrong with the code ?Please advice.
Thanks in advance.

wysota
29th January 2009, 11:47
The code above only schedules a download of the file but it doesn't store it anywhere nor show it anywhere.

rishiraj
29th January 2009, 12:22
Hi,
could you please tell me the procedure for displaying the webpage?Thanks.

wysota
29th January 2009, 12:53
Use QWebView.

jpn
29th January 2009, 13:26
Or QDesktopServices::openUrl() if you want to show the page in an external web browser.

rishiraj
30th January 2009, 05:10
Hi,
I tried 'QWebView' but,I guess I missed something cause I am getting a blank widget
(See attachment)
Didn't make many changes in the code given in the documentation--


QWebView *view=new QWebView();
view->load(QUrl("http://www.google.com/"));
view->show();

Also added QT +=webkit in the .pro file.
Where am I going wrong?
**it worked with QDesktopServices but,I would appreciate it if anyone could tell me where I am going wrong while using QWebView.

wysota
30th January 2009, 10:24
I don't think the code you pasted has anything to do with this, it is more or less correct. Maybe something is blocking the connection?