Qt - how to detect whether the application is running on GNOME or KDE?

喜夏-厌秋 提交于 2019-12-01 18:16:17
schemacs

Use QProcess to run pidof foo, then check its stdout? If this is not what you want, search /proc/.

Normally you shouldn't do this. Generally, if your application behaves differently depending on desktop environment, that will be a nasty surprise for any user that switches between them.

The alternative

Use DE-agnostic commands like xdg-open. Advantages:

  • You don't have to write the logic yourself (xdg-utils already has done this)
  • More user-friendly. It follows the user's actual preferences; many users use one DE but prefer some applications from a different DE.
  • Supports other DEs like XFCE, LXDE, Unity, etc..

For example, instead of opening a URL in Firefox or Konqueror according to the currently-running DE, pass the URL to xdg-open to open it in the user's preferred application. (The user might be a Chromium user.) Don't hard-code nautilus or dolphin for GNOME and KDE; instead open the path using xdg-open.

Similarly, for other forms of interaction with the DE, try to use Freedesktop specifications, rather than trying to guess what DE is running. Standards exist for moving files to the trash, adding system tray applets, and adding files to the Recent Files list, among others.

siride

I believe the correct way to do what pidof does is to look at entries in /proc. There's another thread on this here: Find PID of a Process by Name without Using popen() or system()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!