且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Qt Creator中进入Qt源(在Ubuntu Linux中)

更新时间:2023-11-13 11:38:58

由于Qt Creator使用gdb,因此需要配置gdb。首先要做的就是安装Qt调试符号:

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

或者,对于Qt5:

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

这将安装Qt库的调试符号。 Ubuntu的早期版本有一个愚蠢的错误,需要额外的技巧来纠正这些符号文件,但在当前的版本中工作正常。

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.

这将使gdb步骤在Qt方法,但它没有来源的乐趣。因此,我们需要可以像这样安装的源代码,假设在APT中启用了源代码库:

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

或者,对于Qt5:

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

这将下载源文件,解压缩到当前目录并相应补丁, root权限,除非当前用户不能写当前dir。

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.

最后一件事是通知gdb源位置,这是通过将这个在〜/ .gdbinit 文件中:

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

根据需要添加模块和正确的路径。方便符号链接在这里非常有用,所以我们不必每次我们升级到一个新的Qt版本编辑这个文件。我们只需要下载新的源代码,修补它们并改变符号链接。

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.

注意,即使我们已经安装了调试符号,我们仍然使用Qt库的版本构建。这意味着代码是高度优化的,并且有时在进入Qt二进制文件时会表现得很奇怪。如果它是一个问题,那么有必要在调试模式下构建Qt,单独安装(例如,在/ usr / local / qt4-debug)并告诉Qt Creator使用该特定安装。

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.