問題描述
我在 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 中)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!