[Qt-creator] Debugging helper for forward declared classes (PIMPL)

André Pönitz apoenitz at t-online.de
Sun May 12 13:54:12 CEST 2019


On Sun, May 12, 2019 at 12:42:33PM +0200, resurrection at centrum.cz wrote:
> I have a problem creating a debugging helper for classes that does use only
> forward-declared data member like when using PIMPL:

> - MyClass.h
>     struct MyClassPrivate;
>     class MyClass
>     {
>         MyClassPrivate *d;
>     };
>  
> - MyClass.cpp
>     struct MyClassPrivate
>     {
>         int i;
>     };
>     //...
>  
> And the debugging helper:
>  
> def qdump__MyClass(d, value):
>     with Children(d):
>         d.putSubItem("Number", value["d"]["i"])
>
> Only place when debugging helper for MyClass works is in the implementation file of
> MyClass.cpp. In all other places the MyClassPrivate is just forward declared type and
> the pointer to it is completely opaque to the debugging helper engine unless I step into
> the MyClass.cpp where the type is defined.    I may be asking for the impossible, but is
> there a way to work around this somehow? 

When you know the layout of the private class, you can direcly operate on that. 
E.g.  value.split('...') e.g. works similar to Python's  struct.unpack('...')

I actually prefer this approach nowadays for rarely changing types as it does
not require any debug information for the type, just the address of an instance. 

Andre'



More information about the Qt-creator mailing list