pointers in Locals and Expressions windows of Qt Creator

When debugging in Qt Creator, you can see the real-time values of variables in the Locals window and the Expressions window.

In the above example, c is a variable of ushort type and its value is 113(dec). Both the Locals window and the Expressions window have 3 columns: Name, Value, and Type which correspond to the name of variables, the value of variables and the type of variables. This is understandable for basic types of variables such as int, ushort, etc. But pointer variables have different meanings in the 3 columns. The name column still displays the name of pointer variable, but the value column displays the value pointed by the pointer, not the pointer itself. The type column for pointers also shows the type of the data pointed by the pointer variable, not the type of the pointer variable itself. So, in the above example, the ushort * type of pointer ptr points to a memory that has a value of 61453 and that value is of type ushort. What is the value of the pointer itself? Well, when you hover mouse over the ptr variable in the Locals window or the Expressions window, it will show a pop-up window which displays information about the variable. You can see an entry named “Object Address” which is the value of the ptr itself. Another entry “Pointer Address” is the address of the ptr variable. You can right-click on a pointer variable then select “Open memory editor”/”Open Memory View at Object’s Address” to see the memory fragment pointed by the pointer variable. Note that the memory is arranged from low address to high address so the lower byte of a ushort variable comes before the higher byte. If a pointer points to a class object instead of a basic data type, the value column will be greyed @xxx which xxx is the address of the class object, i.e., this time the value is indeed the value of the pointer. Interestingly, for class object, the value column is also @xxx, i.e., the address of the class object. You need to expand the tree node to see the value of its member variables.

If you like my content, please consider buying me a coffee. Buy me a coffeeBuy me a coffee Thank you for your support!
Posted in

Leave a Reply