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

Stepping into Qt sources in Qt Creator (in Ubuntu Linux)(在 Qt Creator 中进入 Qt 源代码(在 Ubuntu Linux 中))
本文介绍了在 Qt Creator 中进入 Qt 源代码(在 Ubuntu Linux 中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我在 Ubuntu 中使用 Qt Creator.它是从存储库安装的,但就像现在一样,调试时无法进入 Qt 源.

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.

我怎样才能启用它?

推荐答案

由于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 权限.

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.

这篇关于在 Qt Creator 中进入 Qt 源代码(在 Ubuntu Linux 中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Unresolved external symbol quot;public: virtual struct QMetaObject const * __thiscall Parent(未解析的外部符号“public: virtual struct QMetaObject const * __thiscall Parent)
QVector vs QList(QVector 与 QList)
How to create/read/write JSON files in Qt5(如何在 Qt5 中创建/读取/写入 JSON 文件)
Qt: How do I handle the event of the user pressing the #39;X#39; (close) button?(Qt:如何处理用户按下“X(关闭)按钮的事件?)
STL or Qt containers?(STL 还是 Qt 容器?)
Sort filenames naturally with Qt(使用 Qt 自然地对文件名进行排序)