{"id":190,"date":"2020-04-17T17:40:06","date_gmt":"2020-04-17T07:40:06","guid":{"rendered":"http:\/\/menhennitt.com.au\/wordpress\/?p=190"},"modified":"2025-04-23T15:18:30","modified_gmt":"2025-04-23T05:18:30","slug":"visualiser-for-qhostaddress-in-visual-studio","status":"publish","type":"post","link":"https:\/\/menhennitt.com.au\/wordpress\/2020\/04\/17\/visualiser-for-qhostaddress-in-visual-studio","title":{"rendered":"Visualiser for QHostAddress in Visual Studio"},"content":{"rendered":"\n<p>Update: 2025-04-23 There is now a much better visualiser available at <a href=\"https:\/\/github.com\/narnaud\/natvis4qt\" data-type=\"URL\" data-id=\"https:\/\/github.com\/narnaud\/natvis4qt\">https:\/\/github.com\/narnaud\/natvis4qt<\/a>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>I&#8217;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 &#8211; I can&#8217;t see its contents (says something about QHostAddressPrivate). So I finally got around to decoding it. This is very crude &#8211; I&#8217;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.<\/p>\n\n\n\n<p>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:<\/p>\n\n\n\n<p>&lt;Type Name=&#8221;QHostAddress&#8221;&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;DisplayString&gt;{{ IPv4Addr = {(((uint32*)d.d)[8]&gt;&gt;24)&amp;amp;0xff,d}.{(((uint32*)d.d)[8]&gt;&gt;16)&amp;amp;0xff,d}.{(((uint32*)d.d)[8]&gt;&gt;8)&amp;amp;0xff,d}.{(((uint32*)d.d)[8]&gt;&gt;0)&amp;amp;0xff,d} }}&lt;\/DisplayString&gt;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp; &lt;\/Type&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update: 2025-04-23 There is now a much better visualiser available at https:\/\/github.com\/narnaud\/natvis4qt. I&#8217;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 &#8211; I can&#8217;t see its contents (says something about QHostAddressPrivate). So I finally got around to decoding it. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[28,27,29,31,30],"_links":{"self":[{"href":"https:\/\/menhennitt.com.au\/wordpress\/wp-json\/wp\/v2\/posts\/190"}],"collection":[{"href":"https:\/\/menhennitt.com.au\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/menhennitt.com.au\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/menhennitt.com.au\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/menhennitt.com.au\/wordpress\/wp-json\/wp\/v2\/comments?post=190"}],"version-history":[{"count":4,"href":"https:\/\/menhennitt.com.au\/wordpress\/wp-json\/wp\/v2\/posts\/190\/revisions"}],"predecessor-version":[{"id":215,"href":"https:\/\/menhennitt.com.au\/wordpress\/wp-json\/wp\/v2\/posts\/190\/revisions\/215"}],"wp:attachment":[{"href":"https:\/\/menhennitt.com.au\/wordpress\/wp-json\/wp\/v2\/media?parent=190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/menhennitt.com.au\/wordpress\/wp-json\/wp\/v2\/categories?post=190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/menhennitt.com.au\/wordpress\/wp-json\/wp\/v2\/tags?post=190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}