Cannot open files or folders from within Slicer on Linux

I’m using Slicer (stable 5.2.2 and preview 5.3.0-2023-06-17) on Debian 12 (bookworm) Linux with KDE. When I try to open a file using the “Edit” button in a ScriptedLoadableModule or a directory in e.g. the SlicerElastix module I get the following error and the file or directory is not opened:

[CRITICAL][FD] 19.06.2023 22:28:27 [] (unknown:0) - kf.service.services: KApplicationTrader: mimeType "x-scheme-handler/file" not found

If I do the same using Slicer that I compiled myself I get the same error (with some additional errors), but the file or directory is opened:

[CRITICAL][FD] 19.06.2023 22:52:12 [] (unknown:0) - kf.service.services: KApplicationTrader: mimeType "x-scheme-handler/file" not found
[CRITICAL][FD] 19.06.2023 22:52:12 [] (unknown:0) - Hspell: can't open /usr/share/hspell/hebrew.wgz.sizes.
[CRITICAL][FD] 19.06.2023 22:52:12 [] (unknown:0) - kf.sonnet.clients.hspell: HSpellDict::HSpellDict: Init failed

The relevant lines in the code are these in ScriptedLoadableModule:

    def onEditSource(self):
        filePath = slicer.util.modulePath(self.moduleName)
        qt.QDesktopServices.openUrl(qt.QUrl("file:///" + filePath, qt.QUrl.TolerantMode))

and these in SlicerElastix:

  def onShowTemporaryFilesFolder(self):
    qt.QDesktopServices().openUrl(qt.QUrl("file:///" + self.logic.getTempDirectoryBase(), qt.QUrl.TolerantMode))

Does anyone have any ideas about what might be happening here?

Here is the output I get if I run the same commands in the Python console of the pre-built Slicer 5.3.0-2023-06-17 (the files do not open):

>>> qt.QDesktopServices.openUrl(qt.QUrl("file:///home/ben", qt.QUrl.TolerantMode))
True
>>> 
[FD] kf.service.services: KApplicationTrader: mimeType "x-scheme-handler/file" not found
>>> qt.QDesktopServices.openUrl(qt.QUrl("file:///home/ben/test.txt", qt.QUrl.TolerantMode))
True
>>> 
[FD] kf.service.services: KApplicationTrader: mimeType "x-scheme-handler/file" not found

If I run the same commands using Slicer that I compiled myself I get the same output but the files are opened as expected.

The following xdg-open commands also work as expected even though they produce similar warnings/errors:

ben@p1:~$ xdg-open "/home/ben"
kf.service.services: KApplicationTrader: mimeType "x-scheme-handler/file" not found
kf.coreaddons: Expected a KPluginFactory, got a KIOPluginForMetaData
kf.coreaddons: Expected a KPluginFactory, got a KIOPluginForMetaData
kf.coreaddons: Expected a KPluginFactory, got a KIOPluginForMetaData
kf.coreaddons: Expected a KPluginFactory, got a KIOPluginForMetaData

ben@p1:~$ cat "/home/ben/test.txt"
hello

ben@p1:~$ xdg-open "/home/ben/test.txt"
kf.service.services: KApplicationTrader: mimeType "x-scheme-handler/file" not found
Hspell: can't open /usr/share/hspell/hebrew.wgz.sizes.
kf.sonnet.clients.hspell: HSpellDict::HSpellDict: Init failed

See also the discussion on the Debian forum here.

In today’s developer meeting @jcfr suggested to look at the following:

Relevant function on linux QDBusMessage xdgDesktopPortalOpenUrl(const QUrl &url)

In Qt 6: https://github.com/qt/qtbase/blob/0235de994be7e04aca3456f1260b18313dd45b74/src/gui/platform/unix/qgenericunixservices.cpp#L204-L232

May be related to https://github.com/qt/qtbase/commit/fbfaf5d38b3455bb561e739271986be91a7c7169

as well as XDG_ACTIVATION_TOKEN

I tested this again today on a fresh install of Debian 12 Bookworm in a VirtualBox machine. To test the behavior I clicked the “Open Slicer resource file” in the “General” Application Settings. In the GNOME desktop environment, the slicerrc.py file is opened with LibreOffice writer (although the software used can be configured by the user), but in the KDE/Plasma desktop environment, I get the same behavior as described above.

Also, my Debian installation and self-built Slicer are using Qt 5.15.8 (which is working) whereas the pre-compiled stable and preview Slicer are using 5.15.2 (which is NOT working).

I am guessing that this is a bug in Qt or KDE, which may have been fixed in Qt > 5.15.2. I’ll list any relevant links here:

2 Likes