Setup of Qt Creator to debug into Qt classes

13,284

Solution 1

If you are using a prebuilded version just remap the source code location as described in http://doc.qt.io/qtcreator/creator-debugger-engines.html

Mapping Source Paths

To enable the debugger to step into the code and display the source code when using a copy of the source tree at a location different from the one at which the libraries where built, map the source paths to target paths:

  • Select Tools > Options > Debugger > General > Add.
  • In the Source path field, specify the source path in the debug information of the executable as reported by the debugger.
  • In the Target path field, specify the actual location of the source tree on the local machine.

To get "the source path in the debug information of the executable as reported by the debugger", you can activate the "Use Tooltips in Stack-View when Debugging" option by right-clicking in the Stack View and move the mouse over a specific function call.

Solution 2

You have to compile your own Qt. That's the only way of getting this functionality. You're free to use any IDE you want, including a precompiled one. Simply register your self-compiled Qt as a kit in Qt Creator.

Precompiled Qt simply doesn't ship with files with debug information. You can waste an unbounded amount of time trying to debug into precompiled Qt. It's not possible on Unix platforms since the required debug-information-containing objects are not shipped. Neither is it available on Windows, for the same reason - the .pdb files aren't there for MSVC builds, and the object files aren't there for mingw builds. That's seriously all there's to it.

When building a -debug-and-release build of Qt, you must retain all of the following trees (folders) in order for debugging to work:

  • source,
  • build,
  • install prefix.

I don't really know what prebuilt Qt is for. As far as I'm concerned, it shouldn't be offered: it just confuses the heck out of everyone. It's of no use to end users, and it's of no use to developers - I just can't see debugging seriously without access to Qt sources. It defeats the purpose of there being the sources, in a way. Sure, there should be a prebuilt Qt Creator with the prebuilt Qt libraries that it needs, but this shouldn't be exposed outside of it.

Solution 3

With Xcode, before you step into the Qt library the first time, enter the following command in the LLDB window:

settings set target.source-map /Users/qt/work/qt /path/to/Qt/5.10.1/Src

(Obviously you'll want to change the version number, as relevant).

But suppose Trolltech changes its build directory, what to do then? (Or, how did the community wiki that gave the /Users/qt/work/qt path find it?) You can guess what the path needs to be by editing /path/to/Qt/5.10.1/clang_64/lib/QtCore.framework.dSYM/Contents/Resources/DWARF/QtCore_debug (or any other Qt library) and searching for some paths. "/Users" seems like a good guess. About 2% into the library you'll start seeing sections with a lot of paths like:

../../include/QtCore/../../src/corelib/kernel^@../../include/QtCore       
/../../src/corelib/tools^@global^@/Users/qt/work/qt/qtbase/src/corelib
/../../include/QtCore/../../src/corelib/arch^@/Applications/Xcode.app
/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/<etc>

Look for an absolute path that looks like it could be writable. (/Applications/... would not be a likely build path, for example)

Solution 4

In recent Qt creator (v 4.11) press button "Add Qt Sources" in Tools > Options > Debugger > General and select Qt sources file. Qt5 should be installed by online installer with checked "Qt Debug Information files".

Share:
13,284
Horst Walter
Author by

Horst Walter

Developer / Architect for .net Java EE Qt SAP ABAP JavaScript Further interests: Flight simulation (FSX), aviation

Updated on June 18, 2022

Comments

  • Horst Walter
    Horst Walter about 2 years

    I want to setup Qt Creator (3.0) in a way, that I can debug into the Qt classes. So I download the corresponding src code (http://gitorious.org/qt/qt5) and install it in a directory (e.g. c:\Qt5\src).

    Then I have my own project. Where do I need to set the source code path of Qt (c:\Qt5\src), so I can debug my code, but also into a Qt class where necessary.

    -- Edit:Pavel's comment --

    Pavel has given a good hint: But I am using a precompiled version of Qt/Qt Creator. So I am basically looking for a solution which does not require me to compile from source. Nevertheless a useful hint. Thanks.