Qt debugger and pointers to arrays



  • Hello! Is there any option how to watch the content of whole array from the poiner to it, not just the first item and without help of the memory editor?



  • For a real array, that would be hard, I think. For the Qt container classes you can already do that. Problem would be that an array in an off itself does not have set boundaries. So how would the debugger know how many elements there are? At least, that is as far as I understand the issue.



  • In Visual Studio and some other IDEs, you'd type a comma and the number of elements to watch in the array into the watch window. For example "myArray, 6". The Qt debugger doesn't seem to support this though.



  • In Locals and Watchers, context menu of your pointer's entry, select "Watch Expression". This creates a new watched expression below.

    There, double click on the entry in the "Names" column, and add "@10" to display 10 entries.



  • @MarcelBarker: Why does a "Qt Ambassador" respond in such a way?



  • @Duck I'm not sure what you mean. Andre asked how the debugger would know how many elements there are, and I said how Visual Studio does it. I didn't know about the Qt debugger syntax though, thank you for posting that.



  • [quote author="Duck" date="1305323476"]@MarcelBarker: Why does a "Qt Ambassador" respond in such a way?[/quote]

    What is wrong with Marcel's comment?



  • The @10 trick seems to show 10 entries starting from the address of the pointer as opposed to the address of the object that is pointed by the pointer and thus doesn't seem to do what's needed (display the contents of the array that is pointed at by the pointer). The memory editor seems to give one an option to display pointer or object pointed to, but the "Add Expression Evaluator" doesn't. What am I missing?



  • If something starts at the address of the pointer, you need to deference the pointer before.

    In any case, recent builds of Qt Creator allow you to select from about half a dozen ways to display a pointer in the item's context menu, one of them is as a base of an array of items.



  • Hey there, thank you for the reply. You are correct, picking one of the display options seems to do the trick, so thank you for that tip! I'm not quite sure I understand the first half of your response and am still puzzled that pointer@10 would have the behavior that I described previously - let me know if there's an easy way to make that work.

    thank you!



  • [quote author="Duck" date="1305323195"]In Locals and Watchers, context menu of your pointer's entry, select "Watch Expression". This creates a new watched expression below.

    There, double click on the entry in the "Names" column, and add "@10" to display 10 entries.
    [/quote]

    As Duck say, you must specify the size of array when you inspect it as MyArr@Size for one dimensional array, MyArr@Size2@Size1 for two dimensional array and so on. In there the Size parameter can be a value and the variable from the current scope. Then you can easily collaps and expand your array elements in your whatch list. You can also spesify the Size parameter as SizeN x...x Size2 x Size1, where Size1, Size2,...SizeN are sizes of dimensions of your array. In this case you will see all elements of your array in one column.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.