Stepping into Qt sources in Qt Creator (in Ubuntu Linux)

Since Qt Creator uses gdb, you need to configure gdb. First thing to do is to install Qt debugging symbols:

apt-get install libqt4-dbg

Or, for Qt5:

apt-get install qtbase5-dbg # For the qtbase package

This will install the debugging symbols for Qt libraries. Older releases of Ubuntu had a silly bug that required additional trick to correct those symbol files, but in the current release it works fine.

This will make gdb step inside Qt methods, but it’s no fun without sources. So we need sources which can be installed like this, assuming that the source repository is enabled in the APT:

apt-get source qt4-x11
ln -s qt4-x11-4.7.0 qt # a convenience symlink

Or, for Qt5:

apt-get source qtbase-opensource-src
# Make a link as above, if you wish

This will download the sources, unpack them into the current directory and patch them accordingly, no root privileges needed unless the current dir isn’t writeable by the current user.

And the last thing is to inform gdb of the sources location, which is done by putting this in the ~/.gdbinit file:

dir ~/vita/qt/src/corelib
dir ~/vita/qt/src/gui
dir ~/vita/qt/src/network
dir ~/vita/qt/src/sql

Add modules and correct paths as needed. The convenience symlink is very useful here, so we don’t have to edit this file each time we upgrade to a new Qt version. We only need to download the new sources, patch them and change the symlink.

Note that even we have installed the debugging symbols, we still use the release build of Qt libraries. This means that the code is highly optimized and will sometimes behave very strange when stepping inside Qt binaries. If it is a problem, then it is necessary to build Qt in debug mode, install it separately (say, in /usr/local/qt4-debug) and tell Qt Creator to use that particular installation.

Leave a Comment