QDesktopServices::openUrl(); MacOS Issues
-
We are using the code:
QDesktopServices::openUrl(url);
where url is
"file:///Users/mjackson/Workspace1/DREAM3D-Build/NX-Commercial-Debug-Qt68-Vtk94/Bin/DREAM3DNX_d.app/Contents/Resources/Help/DREAM3DNX/html/Visualization/ApplyingRepresentations.html#outline-opacity"
Note the anchor tag at the end of the URL. This seems to work fine on Windows and Linux, but on MacOS it seems to strip the trailing
#
anchor tag. I couldn't find anything definitive on the internet. I did paste the URL into the terminal and use theopen
command and it also strips the#
tag from the URL.Does the QDesktopServices::openUrl() use this same feature? Does it use the 'open' command underneath the covers?
We are using Qt 6.7/6.8/6.9 for our project.
Thank You for any help.
-
QDesktopServices::openUrl and the open command work the same, but the actual behavior depends on how the default browser handles web URLs or HTML files.
I tried the command open https://en.wikipedia.org/wiki/URL_fragment#Examples on macOS and it worked just fine. I think the issue on your side might be that the default browser isn't handling the anchor tag properly on macOS.
Try copying the URL and pasting it directly into the address bar of your default browser to see if the anchor works as expected.
-
Interesting that your provided URL actually works just fine with Safari, FireFox, Chrome, Brave, and Edge.
Looks like the difference is with "file://" versus "https://". Trying my URL which is "file://" does not work with any of the browsers using the "open" command. So I'm assuming it wouldn't work with QDesktopServices either.
-
Ohhh, I see now, it's a macOS feature, where missing details are just part of the charm. Gotta keep the mystery alive for the Apple fans. 😄
-
@Kevin-Hoang I was looking for some clarity if this is a Qt bug or if QDesktopServices just calls out to the 'open' command. Wasn't really looking for the completely non-helpful sarcasm. You-do-you but I don't typically let me feelings for a particular OS's issues play into my messages. When you get as old as I am they basically all suck. They all have their issues (charms as you would call it). None of that is helpful in this context. I need to figure out if I am barking up the wrong tree, if there is a known work around, or if nothing can be done except to file a bug with Apple.
-
@Kevin-Hoang I was looking for some clarity if this is a Qt bug or if QDesktopServices just calls out to the 'open' command. Wasn't really looking for the completely non-helpful sarcasm. You-do-you but I don't typically let me feelings for a particular OS's issues play into my messages. When you get as old as I am they basically all suck. They all have their issues (charms as you would call it). None of that is helpful in this context. I need to figure out if I am barking up the wrong tree, if there is a known work around, or if nothing can be done except to file a bug with Apple.
@imikejackson
I think you were a little harsh on the poster's slightly light-hearted response, but never mind.Trusting you won't take this wrong, but if you do not get an answer here I would try taking a look at the Qt source for QDesktopServices to see what the MacOS code does presumably in the way of a "system" call if I wanted to understand its behaviour. I don't use MacOS, only Linux & Windows. I suspect just reporting a Qt code issue to Apple would not get you anywhere, they would want to know what system call is used. If you wait for someone else to give you a definitive answer here it might not be forthcoming, Just saying.
-
@imikejackson I'm sorry! It was just a light-hearted comment — I think you might have taken it a bit too seriously. What I meant was that this is to be a macOS issue, not a Qt one.
As for workarounds, you could try setting up a simple local server to serve your HTML with the anchor tag, or create a minimal setup using QWebViewer to handle it within your app, though both options are a bit more complex.
-
I don't think I was harsh at all. The joke is old and been run through time and time and time again. It is a meme at this point that "insert operating system" sucks/hides/screwed up "insert something here".
Looked at the Qt Source code and nothing helps there. That sends you to NSWorkspace::openURL function. Nothing special in the docs for that method either. Until you start getting really specific in Google which after a bit yields:
Which then leads you to:
which basically confirms that the code path that Qt is using is broken for Anchors on MacOS. I would blame Apple for this. Not that they are going to listen.
Now of course, since MacOS is just a meme at this point, doing
osascript -e 'tell application "Safari" to open location "file:///Users/mjackson/Workspace1/DREAM3D-Build/NX-Commercial-Debug-Qt68-Vtk94/Bin/DREAM3DNX_d.app/Contents/Resources/Help/DREAM3DNX/html/Visualization/ApplyingRepresentations.html#outline-opacity"'
does actually open the page + anchor but none of the images are rendered.Chrome, Edge and Brave all do load the images.
What ever.
We spent a bunch of time creating docs that could be served without the need to include QWebView or a built in web server for security purposes. Our clients did not like having those services running, even on the loop-back address and a random port. So we are stuck with local files.
-