Search code examples
c++qtqt5clion

Debugging QT symbols with CLion


Question

How does one get a debug view of properties of QT items? I'm currently using CLion.

For example, the application uses a QModelIndex.

enter image description here

I've gathered from documentation that QModelIndex is used in combination with an AbstractItemModel. It seems like the property m is supposed to be a pointer to that model. How do I view the data associated with this QModelIndex and/or QAbstractItemModel? Shouldn't m be showing me additional properties?

Is my understanding so far off as to make this a pointless question and I should run back for the safe hills of C#, Java, and Python where I belong 😅? Or this is an IDE-issue and using something else (Eclipse? KDevelop? QT Creator Open Source?) would yield better results?

I did follow the CLion Documentation for setting up debug renderers. I used Lekensteyn's qt5printers, which at least allowed some basic types like QString to have a pretty view. But it seems like only a handful of the data types are accessible.

Background

I'm typically a C#, Java, and Python developer, but came across a bug in a tool I use that is C++/QT5 based. I'd like to build a bit more knowledge of real C++ development and thought this might be a good opportunity to dive in and see what I can figure out. I'm realizing I have possibly been spoiled by these languages and am a little lost on something that seems basic.


Solution

  • The memory management mechanism of C++ is quite different from those language you mentioned. For the m you provide is a pointer to c, so the value 0x1aa7120 is correct. It indicates the address in memory the pointer point to.

    If you want to see member variables or functions of m, then use -> operator, like m->checkIndex(). Here is the Qt official documentation for you: QModelIndex and QAbstractItemModel.

    By the way, if you are new to C++ and Qt, I would suggest to use Qt Creator as your IDE, which provides templates and documentations you can refer to.