[Development] Extending Visual Studio's display of Qt classes

Tom Isaacson Tom.Isaacson at navico.com
Sun Sep 16 12:08:05 CEST 2012


I've been working on some networking code recently and I got very frustrated with not being able to see the IP and MAC addresses in QHostAddress and QNetworkInterface whilst debugging in Visual Studio. After a bit of experimentation I was able to add viewers for these classes to autoexp.dat and I've posted these below. But the problem I had is that these classes follow the Pimpl Idiom, so it's impossible for Visual Studio to be able to see the members of the classes in order to display the values. I had to look into the implementation of the private part of the classes then use byte shuffling in autoexp.dat to display them. This means that if the layout of the classes ever changes this method will display the wrong data, which is why I'm not sure if it's a good idea to add this to the Visual Studio Add-In installer. However, if anyone wants to do this then go ahead.

I understand why the Pimpl Idiom is being used here, but I'm wondering if it's actually necessary. It's intended for when the source code of the implementation isn't available so internal variables and function names can be completely hidden. But in the case of Qt, where the source code is available and can even be used to build your own binaries, it seems excessive. It also means that useful displays of debugging data aren't really possible and you have to resort to what I've done below.

Can I suggest that going forward the Pimpl Idiom is dropped and we go back to just using private member variables and functions to prevent them being called from outside the class? Or is there some alternative that would allow VS to see the layout it needs?

QHostAddress|*::QHostAddress{
    preview
    (
        #(
            #if (*((quint32 *)$e.d.d) != 0) (
                #("IPv4=", [*(((quint8 *)$e.d.d) + 3), u],
                ".", [*(((quint8 *)$e.d.d) + 2), u],
                ".", [*(((quint8 *)$e.d.d) + 1), u],
                ".", [*(((quint8 *)$e.d.d) + 0), u])
            ) #elif ((*(((quint32 *)$e.d.d) + 1)) + (*(((quint32 *)$e.d.d) + 2)) + (*(((quint32 *)$e.d.d) + 3)) + (*(((quint32 *)$e.d.d) + 4)) != 0) (
                #("IPv6=",
                [(quint16)((*(((quint8 *)$e.d.d) + 0x04) << 0x8) | (*(((quint8 *)$e.d.d) + 0x05))), x],
                ".",
                [(quint16)((*(((quint8 *)$e.d.d) + 0x06) << 0x8) | (*(((quint8 *)$e.d.d) + 0x07))), x],
                ".",
                [(quint16)((*(((quint8 *)$e.d.d) + 0x08) << 0x8) | (*(((quint8 *)$e.d.d) + 0x09))), x],
                ".",
                [(quint16)((*(((quint8 *)$e.d.d) + 0x0A) << 0x8) | (*(((quint8 *)$e.d.d) + 0x0B))), x],
                ".",
                [(quint16)((*(((quint8 *)$e.d.d) + 0x0C) << 0x8) | (*(((quint8 *)$e.d.d) + 0x0D))), x],
                ".",
                [(quint16)((*(((quint8 *)$e.d.d) + 0x0E) << 0x8) | (*(((quint8 *)$e.d.d) + 0x0F))), x],
                ".",
                [(quint16)((*(((quint8 *)$e.d.d) + 0x10) << 0x8) | (*(((quint8 *)$e.d.d) + 0x11))), x],
                ".",
                [(quint16)((*(((quint8 *)$e.d.d) + 0x12) << 0x8) | (*(((quint8 *)$e.d.d) + 0x13))), x])
            )
        )
    )
    children
    (
        #(
            [d]: [$c.d.d, x]
        )
    )
}


 
QNetworkInterface|*::QNetworkInterface{
    preview
    (
        #(
            [(QString *)(((quint32 *)$e.d.d) + 0x4)]
        )
    )
    children
    (
        #(
            [d]: [$c.d.d, x],
            [QSharedData]: [*(((quint32 *)$c.d.d) + 0x0), u],
            [index]: [*(((quint32 *)$c.d.d) + 0x1), u],
            [flags.i]: [*(((quint32 *)$c.d.d) + 0x2), u],
            [name]: [(QString *)(((quint32 *)$c.d.d) + 0x3)],
            [friendlyName]: [(QString *)(((quint32 *)$c.d.d) + 0x4)],
            [hardwareAddress]: [(QString *)(((quint32 *)$c.d.d) + 0x5)]
        )
    )
}

TOM ISAACSON | SENIOR SOFTWARE DEVELOPER | NAVICO ASIA PACIFIC






More information about the Development mailing list