Results 1 to 6 of 6

Thread: detect if a URL exists or not

  1. #1
    Join Date
    Aug 2009
    Posts
    122
    Thanks
    74
    Qt products
    Qt4
    Platforms
    Windows

    Default detect if a URL exists or not

    Hello!

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

    Qt Code:
    1. QDesktopServices::openUrl(myUrl);
    To copy to clipboard, switch view to plain text mode 

    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!

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: detect if a URL exists or not

    QUrl::isValid

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

  3. The following user says thank you to aamer4yu for this useful post:

    timmu (23rd August 2009)

  4. #3
    Join Date
    Aug 2009
    Posts
    122
    Thanks
    74
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: detect if a URL exists or not

    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!
    Last edited by timmu; 23rd August 2009 at 10:44.

  5. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: detect if a URL exists or not

    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

  6. The following user says thank you to aamer4yu for this useful post:

    timmu (23rd August 2009)

  7. #5
    Join Date
    Sep 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows Symbian S60

    Unhappy Re: detect if a URL exists or not

    No, QDesktopServices's openUrl() does not return "false" if the web address is not found... ???

  8. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: detect if a URL exists or not

    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,
    _

Similar Threads

  1. Qextserual can't detect virtual com-port
    By blm in forum Qt Programming
    Replies: 9
    Last Post: 13th December 2012, 07:45
  2. Check if window with certain title exists
    By devil in forum Qt Programming
    Replies: 5
    Last Post: 21st January 2009, 14:42
  3. qmake exists() function
    By roxton in forum Installation and Deployment
    Replies: 1
    Last Post: 28th December 2008, 19:43
  4. fn+f1 keypress detect
    By oguzy in forum Qt Programming
    Replies: 1
    Last Post: 16th November 2008, 16:21
  5. Replies: 1
    Last Post: 9th March 2007, 21:07

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.