Results 1 to 8 of 8

Thread: Support an application's own URL scheme from both the application and any web browser

  1. #1
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Support an application's own URL scheme from both the application and any web browser

    Hi,

    I would like my cross-platform application (Windows, Linux and OS X) to support its own URL scheme (e.g. myapp://some.stuff/). Indeed, I have some HTML documentation which my users can access from both my application's website as well as from the application itself (using QtHelp and a QWebView widget). So, what I would like is that if I have a link, in my HTML documentation, which points to something like myapp://some.stuff/, then my application would handle that URL, no matter whether that link is opened from my application or some web browser.

    Any ideas?...

    Cheers, Alan.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Support an application's own URL scheme from both the application and any web bro

    Doesn't QUrl do what you need?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Support an application's own URL scheme from both the application and any web bro

    Well, I can, using my QWebView widget, retrieve the URL of the link the user wants to open, and QUrl will indeed tell me about the scheme used by the URL. From there, I can determine what do with that URL. All of that, I can do easily.

    However, there remains the case where the user goes to my application's website and clicks on a link which uses my application's URL scheme. Now, how do I make sure that my application starts (if needed) and then handles the link? This is what I don't yet know how to do.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Support an application's own URL scheme from both the application and any web bro

    From a quick look in to the QUrl documentation I could not see that you can set the application responsible for any specific scheme.
    However, you can subclass it, and check for the used scheme given in the input url.
    If the scheme fits your custom scheme, call QProcess with your application and give the url as parameter.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Support an application's own URL scheme from both the application and any web bro

    I think there is a slight misunderstanding. Assuming I understood you correctly, I don't want my application to call an external application if a URL uses my custom scheme. No, in my case, there are two cases I am interested in:
    1. The user starts my application and check the HTML-based help which is shipped with my application and which I display using a QWebView widget. If the user clicks on a link which URL uses my custom scheme, then I want my application to handle that URL to, say, open its about dialog box.
    2. The user starts his preferred web browser, go to my application's website and then click on a link which URL uses my custom scheme (or directly enters a URL which uses my custom scheme and presses the [Enter] key). At this stage, I want the browser/system to realise that this is a URL which should be handled by my application and not by the browser itself. If my application is not already running, then it should be automatically started. Then, my application should handle the URL in the same way as case #1 above.


    Case #1 is very simple for me to handle. It is case #2 which I am not sure how best to handle.

    This being said, I have done some more googling and it would seem that depending on the platform you target (Windows, Linux and OS X in my case), then things are really too platform specific (see http://kb.mozillazine.org/Register_protocol).

    In the end, it would seem that there is no reliable way of implementing case #2. So, I am starting to think that I should probably only focus on case #1.

  6. #6
    Join Date
    Oct 2012
    Posts
    1
    Platforms
    MacOS X Windows

    Default Re: Support an application's own URL scheme from both the application and any web bro

    As per my understanding, you are trying to connect to your native process. that is the same you are expected to achieve through "custom url".
    try with using http protocol:

    provide your native application support http protocol (works as tiny http server). and from your application pages, call your local applicaiton through http get requests. this mus solve your problem.

  7. #7
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Support an application's own URL scheme from both the application and any web bro

    Thanks, Jai, but I am not sure I am following you here. This being said, I must confess that I don't currently have time to look into it unless you were to have some sample code which I could test?... Whatever the case, I have, since my last message, implemented #1 and it works perfectly fine.

  8. #8
    Join Date
    Dec 2013
    Posts
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Default Re: Support an application's own URL scheme from both the application and any web bro

    Hi jai,

    I like your solution. I'm wondering what to do though, to handle the case that a certain customer cannot have their application listening on port 80 (I must say, many won't be able to because a fair share of people run web servers, depending on the industry of customers you are selling to).

    So our current issue is this: we don't want port 80, and we want to be able to detect which port our application is listening on. This brings us to "protocol handlers". Our native application registers iteslf as the handler to a specific protocol.

    We can thus use: OurSpecificProtocol://some/rest/call

    Our app would open and be able to respond to this. But the question is, what happens on different browsers with this type of request. Can you wrap the call in a javascript try/catch, and if your native app is not responding, fall back to something else...

Similar Threads

  1. Replies: 0
    Last Post: 8th May 2012, 13:29
  2. How to write Qt Browser support Html5 ?
    By Thành Viên Mới in forum Qt Programming
    Replies: 0
    Last Post: 19th December 2011, 08:28
  3. Replies: 1
    Last Post: 13th November 2009, 18:40
  4. Replies: 4
    Last Post: 31st July 2009, 08:04
  5. Replies: 0
    Last Post: 18th February 2008, 10:53

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
  •  
Qt is a trademark of The Qt Company.