It is all about the environment

I've just downloaded Qt 4.5 beta 1 and started playing with it. One thing that I've run into a couple of times now are environment variables. Their usage is quite sparsely documented, and can really prove to be useful. So, to have an excuse to look around in the source, I greped a bit.

grep getenv -r src/ | grep cpp\: | grep -o "\"[A-Z_0-9]*\"" | sed 's/"//g'

The X11 version gives 83 hits, while Qt for Embedded Linux (tp1) gives 101. Mergin the two gives 108 unique strings. The difference between these two is fun to look at, but lets start with the more commonly used version: X11.

The variables BROWSER and DEFAULT_BROWSER are used from the QDesktopServices class. The XDG_CACHE_HOME, XDG_CONFIG_HOME and XDG_DATA_HOME are also used by the same class. These variables are all specified in the XDG Base Directory Specification from freedesktop.

QApplication uses a number of environment variables. First, a whole range of variables regarding sessions and desktop ids: DESKTOP_SESSION, DESKTOP_STARTUP_ID, GNOME_DESKTOP_SESSION_ID and SESSION_MANAGER. Then, there is the KDEHOME directory.

There are a number of tuning variables that affect the QApplication class. I have not over analyzed the following, so correct my explanations if I'm wrong.
  • QT_NO_GLIB - prevents Qt from using GLib's event loop.
  • QT_SLOW_TOPLEVEL_RESIZE - used to solve KDE bug #157659.
  • QT_USE_NATIVE_WINDOWS - makes Qt flicker :-)
  • QT_X11_NO_FONTCONFIG - makes Qt not to use X11's FontConfig.
  • QT_X11_NO_MITSHM - stops Qt form using the MIT-SHM X11 extension.
  • QT_X11_NO_XRENDER - prevents Qt from using the Xrender extension.
The QSslSocket class uses DYLD_LIBRARY_PATH and LD_LIBRARY_PATH through qsslsocket_openssl_symbols.cpp.

GTK2_RC_FILES is used to find GTK symbols when styling. KDEDIRS and KDE_SESSION_VERSION are also used by the style classes.

HOME is used from the classes QFSFileEngine and QPrintDialog.

Phonon uses a whole bunch of environment variables. I will not dive deeper into these, at least not for now.
The LANG variable is used by QLocale as expected, but also by QTextCodec and QIconvCodec. The variables prefixed with LC_ are also used by the same classes.
  • LC_ALL (QLocale, QIconvCodec, QTextCodec)
  • LC_CTYPE (QIconvCodec, QTextCodec)
  • LC_NUMERIC (QLocale)
The Qt 3 support version of QFileDialog uses LOGNAME when trying to determine the location of ~.

LPDEST is used by QPdf and QPrinterInfo. The same classes also use the NGPRINTER, NPRINTER and PRINTER variables.

MALLOCSTATS is ued by the webkit JavaScriptCore component. Continuing in the webkit sources, the WebCore component uses MOZILLA_HOME, MOZ_PLUGIN_PATH, QT_WEBKIT_LOG and QTWEBKIT_PLUGIN_PATH.

One of the most popular environment variables, PATH, is used by FreeType, libtiff, QProcess, QCoreApplication as well as Q3Process.

QDBUS_DEBUG can be used to turn on d-bus debugging.

The QT4_IM_MODULE variable controls the input method to use.

QT_ACCESSIBILITY makes it possible to turn of accessibility (just set it to a non-one value).

By setting QT_CRASH_OUTPUT to a file name, a backtrace is written there when a signal is encountered.

Set QT_DEBUG_PLUGINS to a non-zero value to enable debugging of Qt plug-ins.

The QTestLib module uses a number of variables:
  • QTEST_COLORED - controlls if the output should be coloured or not.
  • QTEST_EVENT_DELAY - delays events.
  • QTEST_KEYEVENT_DELAY - delays key events.
  • QTEST_KEYEVENT_VERBOSE - verbose output for keyboard events.
  • QTEST_MOUSEEVENT_DELAY - delays mouse events.
To make Qt exit on warnings, set QT_FATAL_WARNINGS.

Now I'm about half-way through my list and, as all of you knows, time flies when you're having fun. Next time, I'll resume at QT_FLUSH_PAINT!



At 7:10 PM, Anonymous Anonymous said...

All the PHONON_GST_* vars are not phonon general, but only used by the gstreamer backend for phonon.


At 8:10 PM, Blogger brendan said...

I had a problem where qt apps took a long time(30 seconds) to start on computers with a nfs mounted root FS. QT_X11_NO_FONTCONFIG fixed the problem. Thanks!

At 8:13 PM, Blogger Johan Thelin said...

Ah, understandable, as I am looking at the Linux variants of Qt. Can you tell us how they are used?

At 11:00 AM, Blogger vivo said...

inspired from a response from your (http://der-dakon.net/blog/KDE/use-the-tools.html) post , that was trying to remove as much programs invocation as it was possible ...

your grep may be more efficient in this form:

find src -name \*.cpp -print0 | xargs -0 sed '/getenv.*"[A-Z_0-9]*"/s/^.*"\(.*\)".*$/\1/;t;d'

P.S. posting here because that blog seem to not admit comments :(

At 11:05 AM, Blogger Johan Thelin said...

I saw his blog today - interesting to read.

At 11:08 PM, Anonymous lemrey said...

QT_X11_NO_MITSHM saved my life dud
i was getting some mit-shm errors on
freebsd using qt 4.6.1 and that solved it, thank you sooo much

At 11:20 PM, Anonymous Anonymous said...

you saved my life dud
i was getting some mit-shm related error on freebsd using qt 4.6.1
and exporting QT_X11_NO_MITSHM solved it


Post a Comment

<< Home