PDA

View Full Version : detect if a URL exists or not



timmu
23rd August 2009, 10:37
Hello!

Is it possible to use Qt to detect if a website exists or not without opening it in a browser window with:



QDesktopServices::openUrl(myUrl);


If you have to open a website as shown above in order to test it, how do you then test it if it exists (opens properly) or not?

Thanks!

aamer4yu
23rd August 2009, 10:45
QUrl::isValid :)

Psst.. : Search Qt Assistant too... it will answer many questions, just needs a little searching :)

timmu
23rd August 2009, 10:57
Aamer4yu, thanks much for your answer!

The problem that I see with "url.isValid()" is that it only seems to detect whether the URL syntax is valid. I' like to detect if the webiste exists. I use IE and when I open a website that doesn't exist (for example http://www.wolf222.com) the browser opens a window where it says that the website doesn't exist and isValid() doesn't think anything is wrong.

Is it possible to detect if a webiste exists?

Is the only way to do it to open the HTML file of the error message and read it and try to detect if it is a standard error message? If that is the case, how do you open an HTML from the internet so that you could read it like a normal file? I use Qt 4.4.

Thanks again!

aamer4yu
23rd August 2009, 16:09
Doesnt QDesktopServices::openUrl return bool ? If it returns false, it means the url was not found.

Also you can have a look at QNetworkReply. It as one network error - QNetworkReply::HostNotFoundError . I havent worked with web related stuff, so can only hint you. You will need to dig deeper :)

momchil
25th January 2013, 20:13
No, QDesktopServices's openUrl() does not return "false" if the web address is not found... :( ???

anda_skoa
27th January 2013, 14:16
Have a look at QNetworkAccessManager::get()

I.e. do a HTTP get call on the URL. if this succeeds then opening in a browser should succeed as well.

Cheers,
_