Sunday 18 January 2015

Resource file access in Qt

Qt resources in qrc files have a Prefix and a Path (which is the file path relative to the qrc file).

To access a resource as if it were a file, you need to use both, with a colon at the start to indicate that it's a resource, not an object on disk:

QFile::exists(":/Prefix/rel_Path/file.ext")

ostringstream is the perfect C++ replacement for sprintf, except...

ostringstream is the perfect C++ replacement for sprintf, except for trying to debug its contents in Visual Studio.
Add this to Microsoft Visual Studio 12.0\Common7\Packages\Debugger\Visualizers\stl.natvis:

<Type Name="std::basic_ostringstream&lt;char,*&gt;">
<DisplayString>{_Mystrbuf->_Gfirst},s</DisplayString>
<StringView>_Mystrbuf->_Gfirst,s</StringView>
<Expand>
<Item Name="[state]">_Mystate</Item>
<ExpandedItem>_Mystrbuf->_Gfirst</ExpandedItem>
</Expand>
</Type>