Boost C++ Libraries: Ticket #8846: Improvements to Spirit Qi Qt QString custom_string.cpp example https://svn.boost.org/trac10/ticket/8846 <p> Tim Angus asked me to submit this patch (Boost Trac was complaining for him with "Submission rejected as potential spam"). </p> <p> There is an example of how to use Qi with a custom string (in this case a QString from the Qt framework). This is very helpful but it doesn't work in conjunction with the debug facilities. The following patch fixes this by adding a couple of template specialisations. </p> <p> Patch: </p> <pre class="wiki">Index: libs/spirit/example/qi/custom_string.cpp =================================================================== --- libs/spirit/example/qi/custom_string.cpp (revision 85071) +++ libs/spirit/example/qi/custom_string.cpp (working copy) @@ -34,6 +34,26 @@ return true; } }; + + // Test if a QString is empty (required for debug) + template &lt;&gt; + struct is_empty_container&lt;QString&gt; + { + static bool call(QString const&amp; c) + { + return c.isEmpty(); + } + }; + + // Define how to stream a QString (required for debug) + template &lt;typename Out, typename Enable&gt; + struct print_attribute_debug&lt;Out, QString, Enable&gt; + { + static void call(Out&amp; out, QString const&amp; val) + { + out &lt;&lt; val.toStdString(); + } + }; </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8846 Trac 1.4.3 anonymous Thu, 11 Dec 2014 13:44:37 GMT <link>https://svn.boost.org/trac10/ticket/8846#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8846#comment:1</guid> <description> <p> This is great ! I has exactly the same problem (debugging QStrings did no longer work after a Qt update) and this solved it. Many thanks ! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Thu, 11 Dec 2014 14:58:21 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8846#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8846#comment:2</guid> <description> <p> Could you please prepare a pull request instead: <a class="ext-link" href="https://github.com/boostorg/spirit"><span class="icon">​</span>https://github.com/boostorg/spirit</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Mateusz Loskot</dc:creator> <pubDate>Mon, 15 Dec 2014 10:02:36 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8846#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8846#comment:3</guid> <description> <p> @djowel Sure, here it is <a class="ext-link" href="https://github.com/boostorg/spirit/pull/73"><span class="icon">​</span>https://github.com/boostorg/spirit/pull/73</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Mon, 15 Dec 2014 11:26:05 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/8846#comment:4 https://svn.boost.org/trac10/ticket/8846#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket