Linux: When Qt fails to open a file with the system default application fallback to xdg-open explicitly

Who knows what Qt does these days. Portals and desktop heauristics and
platform plugins. Sigh. Linux is such a clusterfuck.
This commit is contained in:
Kovid Goyal 2023-11-25 07:31:45 +05:30
parent 4bd1ea9f70
commit 4a7c5dbd5a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -1462,7 +1462,18 @@ def open_url(qurl):
# Qt 5 requires QApplication to be constructed before trying to use # Qt 5 requires QApplication to be constructed before trying to use
# QDesktopServices::openUrl() # QDesktopServices::openUrl()
ensure_app() ensure_app()
QDesktopServices.openUrl(qurl) ok = QDesktopServices.openUrl(qurl)
if not ok:
# this happens a lot with Qt 6.5.3 on some Linux distros
print('QDesktopServices.openUrl() failed for url:', qurl, file=sys.stderr)
if islinux:
if qurl.isLocalFile():
cmd = ['xdg-open', qurl.toLocalFile()]
else:
cmd = ['xdg-open', qurl.toString()]
if DEBUG:
print('Running opener:', cmd)
subprocess.Popen(cmd, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
def safe_open_url(qurl): def safe_open_url(qurl):