1

I am trying to find the .desktop file for qtcreator, so I write this:

$ for p in ${XDG_DATA_DIRS//:/ }; do
    grep -rni 'qtcreator' $p;
done

And here is the most relevant lines:

/usr/share/app-install/desktop/qtcreator-plugin-ubuntu:ubuntusdk.desktop:2:X-AppInstall-Package=qtcreator-plugin-ubuntu
/usr/share/app-install/desktop/qtcreator-plugin-ubuntu:ubuntusdk.desktop:6:Exec=qtcreator %F
/usr/share/app-install/desktop/qtcreator-plugin-ubuntu:ubuntusdk.desktop:7:Icon=ubuntu-qtcreator
/usr/share/app-install/desktop/qtcreator:qtcreator.desktop:2:X-AppInstall-Package=qtcreator
/usr/share/app-install/desktop/qtcreator:qtcreator.desktop:6:Exec=qtcreator %F
/usr/share/app-install/desktop/qtcreator:qtcreator.desktop:7:Icon=QtProject-qtcreator
/usr/share/app-install/desktop/qhimdtransfer:qhimdtransfer.desktop:12:#Icon=qtcreator_logo_32

I think the qtcreator:qtcreator.desktop is the desktop entry for QtCreator, so I open it and find out:

[Desktop Entry]
X-AppInstall-Package=qtcreator
X-AppInstall-Popcon=292
X-AppInstall-Section=universe

Exec=qtcreator %F
Icon=QtProject-qtcreator
Type=Application
Terminal=false
Name=Qt Creator
GenericName=Integrated Development Environment
MimeType=text/x-c++src;text/x-c++hdr;text/x-xsrc;application/x-designer;application/vnd.nokia.qt.qmakeprofile;application/vnd.nokia.xml.qt.resource;
Categories=Qt;Development;IDE;
InitialPreference=9

X-Ubuntu-Gettext-Domain=app-install-data

qtcreator is not in the variable $PATH of the shell. But I can still launch QtCreator in gnome unity.

From the freedesktop-exec-variables I noticed

If no full path is provided the executable is looked up in the $PATH environment variable used by the desktop environment.

Question

Is $PATH environment variable of a desktop environment different from that is a shell?

If so, where is the config file containing the $PATH variable for desktop environment?

I install a newer version of QtCreator then launch QtCreator in desktop and find out it references to the newer version without changing the qtcreator:qtcreator.desktop file. I think there is something to with the path of qt?

Desktop environment: gnome

OS: ubuntu16.04

Edit

The actual problem I encountered was not about $PATH(see my answer blow). Gilles' answer is actually the answer to `Is $PATH environment variable of a desktop environment different from that in a shell?' so I accepted it in case that someone has the same doubt as me.

z.h.
  • 994

2 Answers2

2

Is $PATH environment variable of a desktop environment different from that is a shell?

It may be.

The environment of a program does not come from a file, unless the program goes out of its way to read environment variables from a file. Each process inherits the environment of its parent. Reading environment variables from a file is part of the job of the program you run upon login (a shell when logging in in text mode, a session manager or the program that acts as such when logging in in a graphical environment). So normally, if you use your desktop environment and open a shell in a terminal, that shell would have the same environment as the desktop environment.

However, in practice, this may not be the case, because there's a ton of advice on the web telling people to put environment variable definitions in .bashrc. That's a bad idea because it means that these environment variables are not available to programs started directly from the GUI, rather than started from a terminal. But if you've done that, you may find that you have different environment variables in a terminal compared to what you have in the desktop environment and in programs not launched from a terminal.

Putting environment variable definitions in ~/.profile works on most systems. I think it works for Gnome on Ubuntu 16.04 as long as you don't activate Wayland (which breaks a lot of things, including login settings, and doesn't always offer a way to recover).

In any case, the usual symptoms of putting environment variables in the wrong place is that environment variables are present in a terminal, but missing in the desktop environment. For it to be the other way round, you would have to have something unusual in your shell startup files.

qtcreator is not in the variable $PATH of the shell.

I very much doubt it, if it's installed. Ubuntu ships qtcreator in /usr/bin which is where most programs are located.

But note that $PATH has nothing to do with the location of the .desktop file. $PATH is for application programs, not for .desktop files. If you're looking for the .desktop file for qtcreator, and you have the qtcreator package installed, you can just search for the file:

$ locate qtcreator.desktop
/usr/share/applications/qtcreator.desktop

/usr/share/applications is the standard location for .desktop files.

If you've installed your own version of QtCreator in addition to the one in Ubuntu, then you should ensure that qtcreator is in the command search path, i.e. $PATH. If you installed it system-wide, you should have it available as /usr/local/bin/qtcreator, which is on the command search path before /usr/bin, so you'll get your version in preference to the system one. If you installed it on your account, create a symbolic link from wherever the qtcreator executable is to ~/bin/qtcreator, i.e. to the directory bin under your home directory (if this directory doesn't exist, create it). Ubuntu's default .profile adds ~/bin to the front of $PATH.

  • Thanks for the detailed explanation @Gilles. qtcreator is not in /usr/bin because I uninstalled the original one and install from source again but didn't add to the $PATH. Although the true problem is I found the wrong .desktop file, your answer suits the title so I am gonna accept this. – z.h. Jul 01 '18 at 10:22
0

Turns out that $XDG_DATA_DIRS is not the only search path for *.desktop file. So I found the wrong QtCreator desktop entry file.

See the XDG Base Directory Specification

There is a single base directory relative to which user-specific data files should be written. This directory is defined by the environment variable $XDG_DATA_HOME.

$XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored. If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used.

$XDG_DATA_DIRS defines the preference-ordered set of base directories to search for data files in addition to the $XDG_DATA_HOME base directory. The directories in $XDG_DATA_DIRS should be seperated with a colon ':'.

I found the true QtCreator desktop entry file ~/.local/share/application/DigiaQt-qtcreator-community.desktop.

The Exec line is Exec=/home/user/Qt/Tools/QtCreator/bin/qtcreator, so the problem is not about $PATH.

I installed both the older and newer version of QtCreator from source. There is an InstallationLog.txt under Qt directory. The action of copying the desktop file to ~/.local/share is documented there.

z.h.
  • 994