简体   繁体   中英

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

I'm using Qt Creator in Ubuntu. It's installed from the repositories but as it is now, there is no way to step into the Qt sources when debugging.

How can I enable that?

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.

The only way i made it work on Ubuntu is building Qt from sources with configure -debug . Everything started to work like a charm afterwards.

Qt binary packages for Linux don't contain debug symbols and therefore the debugger doesn't know files or line numbers where to jump to. You need to build Qt yourself with -debug configure option if you want to be able to debug Qt code.

Instructions from Sergey Tachenov instructions would only work if you build your application against the Qt version that you can find from Ubuntu repositories.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM