How to register application to handle custom uri:// scheme?
-
I'd like my Qt application to be opened whenever
myapplication://is invoked on Windows, macOS, and Linux - does anyone have any experience with setting this up?I've looked around in Qt documentation but this doesn't seem to be covered, and the details on the web are scarce or outdated for 2019. Thanks!
-
This is OS-specific and Qt can't do anything for it. For Windows see e.g. https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa767914(v=vs.85)?redirectedfrom=MSDN
-
For the benefit of others ... In order to do this I'm pursuing the use of an IFW "Execute" operation to run a PowerShell script that modifies the registry.
https://forum.qt.io/topic/107524/qt-installer-framework-execute-commandI think that @christian might be overstating the "can't" part of his message, given how many OS-specific facilities have recently been generalized so nicely in Qt.
-
... and six years later the answer is essentially the same.
The action of launching your application when the URI scheme (or document type) is "executed" is entirely outside the application. This is an operating system specific configuration that, as you have noticed, can be achieved at install time by your installer of choice. That's generally the cleanest way to get it done.
For this specific example on Windows, you could put OS-specific, first-time-run code in your application (using QSettings as a wrapper on the Windows registry) but it would require executing at least once with elevated privileges. You might do this in your installer...
This is not a run time facility of your application that the Qt library can generalise.
-
https://doc.qt.io/qt-6/qdesktopservices.html#setUrlHandler does it for macOS/iOS/Android, but not for Windows/Linux I believe