Posts Tagged Visual Studio
Visualiser for QHostAddress in Visual Studio
I’ve been using Visual Studio to debug Qt programs for some time now. Every time I come to a variable of type QHostAddress, I cringe – I can’t see its contents (says something about QHostAddressPrivate). So I finally got around to decoding it. This is very crude – I’m sure it can be done more elegantly. It works for Qt-5.9.8 although I would expect other versions to be very similar. It only works for IPv4 addresses.
To enable it, edit your qt5.natvis file (mine lives in C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Packages\Debugger\Visualizers). Add the following snippet inside the top level of the AutoVisualizer section:
<Type Name=”QHostAddress”>
<DisplayString>{{ IPv4Addr = {(((uint32*)d.d)[8]>>24)&0xff,d}.{(((uint32*)d.d)[8]>>16)&0xff,d}.{(((uint32*)d.d)[8]>>8)&0xff,d}.{(((uint32*)d.d)[8]>>0)&0xff,d} }}</DisplayString>
</Type>