View Array contents in Qt Creator debugger

前端 未结 5 1918
傲寒
傲寒 2021-01-08 01:25

I am using Qt on Ubuntu. When I debug I only see the very first value of the array in Locals and Watchers. How can I view all the array contents?

struct node         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-08 01:49

    Two dimensional arrays sometimes cannot be displayed that way. There is a work-around. First, declare a two-dimensional array as a one-dimensional array like this:

        int width = 3;
        int height = 4;
        int* array2D = new int [width*height];
        int x,y;
        for(x=width-1;x>-1;x--)
            for(y=height-1;y>-1;y--)
                array2D[x*height + y] = -1; // mark a breakpoint here!
        // add to expression evaluator: (int[3][4]) *array2D
        delete [] array2D;
    

    Then add (int[3][4]) *array2D to the expression evaluator. Unfortunately you have to index the array your self, but you can write a special-purpose inline function or use another encapsulation method to make it slightly cleaner.

提交回复
热议问题