简体   繁体   English

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

[英]Stepping into Qt sources in Qt Creator (in Ubuntu Linux)

I'm using Qt Creator in Ubuntu.我在 Ubuntu 中使用 Qt Creator。 It's installed from the repositories but as it is now, there is no way to step into the Qt sources when debugging.它是从存储库安装的,但就像现在一样,调试时无法进入 Qt 源代码。

How can I enable that?我怎样才能启用它?

Since Qt Creator uses gdb, you need to configure gdb.由于Qt Creator 使用gdb,所以需要配置gdb。 First thing to do is to install Qt debugging symbols:首先要做的是安装Qt调试符号:

apt-get install libqt4-dbg

Or, for Qt5:或者,对于 Qt5:

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

This will install the debugging symbols for Qt libraries.这将为 Qt 库安装调试符号。 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.旧版本的 Ubuntu 有一个愚蠢的错误,需要额外的技巧来纠正这些符号文件,但在当前版本中它运行良好。

This will make gdb step inside Qt methods, but it's no fun without sources.这将使 gdb 进入 Qt 方法,但没有源就没有乐趣。 So we need sources which can be installed like this, assuming that the source repository is enabled in the APT:所以我们需要可以像这样安装的源,假设在 APT 中启用了源存储库:

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

Or, for Qt5:或者,对于 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.这将下载源代码,将它们解压缩到当前目录并相应地修补它们,除非当前用户不可写入当前目录,否则不需要 root 权限。

And the last thing is to inform gdb of the sources location, which is done by putting this in the ~/.gdbinit file:最后一件事是通知 gdb 源位置,这是通过将其放在~/.gdbinit文件中来完成的:

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.方便的符号链接在这里非常有用,因此我们不必每次升级到新的 Qt 版本时都编辑此文件。 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.请注意,即使我们已经安装了调试符号,我们仍然使用 Qt 库的发布版本。 This means that the code is highly optimized and will sometimes behave very strange when stepping inside Qt binaries.这意味着代码经过高度优化,有时在进入 Qt 二进制文件时会表现得非常奇怪。 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.如果有问题,则需要在调试模式下构建 Qt,单独安装(例如,在 /usr/local/qt4-debug 中)并告诉 Qt Creator 使用该特定安装。

The only way i made it work on Ubuntu is building Qt from sources with configure -debug .我让它在 Ubuntu 上工作的唯一方法是使用configure -debug从源代码构建 Qt 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. Linux 的 Qt 二进制包不包含调试符号,因此调试器不知道要跳转到的文件或行号。 You need to build Qt yourself with -debug configure option if you want to be able to debug Qt code.如果您希望能够调试 Qt 代码,您需要使用 -debug 配置选项自己构建 Qt。

Instructions from Sergey Tachenov instructions would only work if you build your application against the Qt version that you can find from Ubuntu repositories.来自 Sergey Tachenov 的说明只有在您针对可从 Ubuntu 存储库中找到的 Qt 版本构建应用程序时才有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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