<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Erata.NET</title>
	<atom:link href="http://www.erata.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.erata.net</link>
	<description>If we don't have the solution you have the wrong problem</description>
	<pubDate>Tue, 08 Apr 2008 10:44:16 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Wordpress WassUp Error</title>
		<link>http://www.erata.net/programming/wordpress-wassup-error/</link>
		<comments>http://www.erata.net/programming/wordpress-wassup-error/#comments</comments>
		<pubDate>Mon, 07 Apr 2008 09:26:34 +0000</pubDate>
		<dc:creator>eti</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[dashboard]]></category>

		<category><![CDATA[error]]></category>

		<category><![CDATA[syntax error]]></category>

		<category><![CDATA[wassup]]></category>

		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.erata.net/?p=40</guid>
		<description><![CDATA[<p>I&#8217;ve upgraded the wassup plugin to the latest version ( 1.5 ) and an error started to show in the pages:</p>
<p>[ wp_wassup_tmp' doesn't exist ]</p>
<p>The solution is to deactivate the plugin and then reactivate it&#8230; witch should be the right&#8230;</p><script type="text/javascript">SHARETHIS.addEntry({ title: "Wordpress WassUp Error", url: "http://www.erata.net/programming/wordpress-wassup-error/" });</script>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve upgraded the wassup plugin to the latest version ( 1.5 ) and an error started to show in the pages:</p>
<p>[ wp_wassup_tmp' doesn't exist ]</p>
<p>The solution is to deactivate the plugin and then reactivate it&#8230; witch should be the right way to upgrade your plugins.</p>
<p><strong>Update:</strong></p>
<p>I also get a syntax error from the wassup plugin, on the dashboard:<br />
<cite><br />
<strong>WordPress database error:</strong> [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND 1207656596' at line 1]<br />
<code>SELECT COUNT(DISTINCT wassup_id) AS itemstot FROM wp_wassup WHERE wassup_id IS NOT NULL  AND timestamp BETWEEN  AND 1207656596</code><br />
</cite></p>
<p>It seems that the errore comes from a debug query that was left in the wassupDashChart() function. To fix the error you need to comment two lines (1631,1632) of code in wassup.php:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// This is the function to print out a chart&#8217;s preview in the dashboard</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> wassupDashChart<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><a href="http://www.php.net/global"><span class="kw3">global</span></a> <span class="re0">$wpdb</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="re0">$table_name</span> = <span class="re0">$wpdb</span>-&gt;<span class="me1">prefix</span> . <span class="st0">&quot;wassup&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$to_date</span> = wassup_get_time<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$Chart</span> = <span class="kw2">New</span> MainItems;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$Chart</span>-&gt;<span class="me1">tableName</span> = <span class="re0">$table_name</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$Chart</span>-&gt;<span class="me1">to_date</span> = <span class="re0">$to_date</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//$itemstot = $Chart-&gt;calc_tot(&quot;count&quot;, $search, null, &quot;DISTINCT&quot;);</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//print $itemstot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&#8216;&lt;h3&gt;WassUp Stats &lt;cite&gt;&lt;a href=&quot;admin.php?page=wassup&quot;&gt;More &amp;amp;raquo;&lt;/a&gt;&lt;/cite&gt;&lt;/h3&gt;&#8217;</span>;</div>
</li>
<li class="li2">
<div class="de2"><a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="re0">$Chart</span>-&gt;<span class="me1">TheChart</span><span class="br0">&#40;</span><span class="nu0">1</span>, <span class="st0">&quot;400&quot;</span>, <span class="st0">&quot;125&quot;</span>, <span class="st0">&quot;&quot;</span>, <span class="re0">$wassup_options</span>-&gt;<span class="me1">wassup_chart_type</span>, <span class="st0">&quot;bg,s,00000000&quot;</span>, <span class="st0">&quot;dashboard&quot;</span>, <span class="st0">&quot;left&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span> <span class="co1">//end function wassupDashChart</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p><a href="http://sharethis.com/item?&wp=2.5.1&amp;publisher=94167405-13d5-4f0e-b754-1ab80e6262f2&amp;title=Wordpress+WassUp+Error&amp;url=http%3A%2F%2Fwww.erata.net%2Fprogramming%2Fwordpress-wassup-error%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.erata.net/programming/wordpress-wassup-error/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Wordpress Updated to 2.5</title>
		<link>http://www.erata.net/news/wordpress-updated-to-25/</link>
		<comments>http://www.erata.net/news/wordpress-updated-to-25/#comments</comments>
		<pubDate>Wed, 02 Apr 2008 11:50:57 +0000</pubDate>
		<dc:creator>eti</dc:creator>
		
		<category><![CDATA[News]]></category>

		<category><![CDATA[update]]></category>

		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.erata.net/?p=39</guid>
		<description><![CDATA[<p>I&#8217;ve updated wordpress to the latest stable version and all the plugins seem to work ok.</p>
<script type="text/javascript">SHARETHIS.addEntry({ title: "Wordpress Updated to 2.5", url: "http://www.erata.net/news/wordpress-updated-to-25/" });</script>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve updated wordpress to the latest stable version and all the plugins seem to work ok.</p>
<p><a href="http://sharethis.com/item?&wp=2.5.1&amp;publisher=94167405-13d5-4f0e-b754-1ab80e6262f2&amp;title=Wordpress+Updated+to+2.5&amp;url=http%3A%2F%2Fwww.erata.net%2Fnews%2Fwordpress-updated-to-25%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.erata.net/news/wordpress-updated-to-25/feed/</wfw:commentRss>
		</item>
		<item>
		<title>myWeather widget</title>
		<link>http://www.erata.net/programming/myweather-widget/</link>
		<comments>http://www.erata.net/programming/myweather-widget/#comments</comments>
		<pubDate>Thu, 06 Dec 2007 11:55:35 +0000</pubDate>
		<dc:creator>eti</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[myweather]]></category>

		<category><![CDATA[plugin]]></category>

		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.erata.net/weblog/programming/2007/12/06/myweather-widget/</guid>
		<description><![CDATA[<p>To create a quick and dirty widget from myWeather wordpress plugin just add the following to the end of myweather.php</p>
<p></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&#160;</div>
</li>
<li class="li1">
<div class="de1">function widget_weather_init&#40;&#41; &#123;</div>
</li>
<li class="li1">
<div class="de1">&#160;</div>
</li>
<li class="li1">
<div class="de1">&#160; &#160; if &#40; !<a href="http://www.php.net/function_exists">function_exists</a>&#40;&#8216;register_sidebar_widget&#8217;&#41; &#41;</div>
</li>
<li class="li2">
<div class="de2">&#160; &#160; &#160; &#160; &#160; &#160; return;</div>
</li>
<li class="li1">
<div class="de1">&#160; &#160; register_sidebar_widget&#40;<a href="http://www.php.net/array">array</a>&#40;&#8216;Weather&#8217;, &#8216;widgets&#8217;&#41;, &#8216;widget_weather&#8217;&#41;; &#160; &#160;</div>
</li>
<li class="li1">
<div class="de1">&#125;</div>
</li>
<li class="li1">
<div class="de1">&#160;</div>
</li>
<li class="li1">
<div class="de1">function widget_weather&#40;$args&#41;</div>
</li>
<li class="li2">
<div class="de2">&#123;</div>
</li>
<li class="li1">
<div class="de1">&#160;&#8230;</div></li></ol></div><script type="text/javascript">SHARETHIS.addEntry({ title: "myWeather widget", url: "http://www.erata.net/programming/myweather-widget/" });</script>]]></description>
			<content:encoded><![CDATA[<p>To create a quick and dirty widget from myWeather wordpress plugin just add the following to the end of myweather.php</p>
<p><span id="more-35"></span></p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> widget_weather_init<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span> !<a href="http://www.php.net/function_exists"><span class="kw3">function_exists</span></a><span class="br0">&#40;</span><span class="st0">&#8216;register_sidebar_widget&#8217;</span><span class="br0">&#41;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; register_sidebar_widget<span class="br0">&#40;</span><a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st0">&#8216;Weather&#8217;</span>, <span class="st0">&#8216;widgets&#8217;</span><span class="br0">&#41;</span>, <span class="st0">&#8216;widget_weather&#8217;</span><span class="br0">&#41;</span>; &nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> widget_weather<span class="br0">&#40;</span><span class="re0">$args</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <a href="http://www.php.net/extract"><span class="kw3">extract</span></a><span class="br0">&#40;</span><span class="re0">$args</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="re0">$before_widget</span> . <span class="re0">$before_title</span> . <span class="re0">$title</span> . <span class="re0">$after_title</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; wp_myweather<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="re0">$after_widget</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">add_action<span class="br0">&#40;</span><span class="st0">&#8216;widgets_init&#8217;</span>, <span class="st0">&#8216;widget_weather_init&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>Also the part where you search for the city could be added as a control for the widget but i didn&#8217;t relay need it to be .</p>
<p>MyWeather plugin&#8217;s <a href="http://www.thedeveloperinside.com/blog/myweather-20-released/" title="MyWeather">homepage</a>.</p>
<h1><a id="update">Update</a></h1>
<p>If you have multiple users with different credentials on your blog and you are the only administrator you can restrict the access to myWeather plugin administration interface by changing the function <em>myweather_to_admin()</em> to look like this (use 10 instead of 1 for required level) :</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> myweather_to_admin<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><a href="http://www.php.net/function_exists"><span class="kw3">function_exists</span></a><span class="br0">&#40;</span><span class="st0">&#8216;add_submenu_page&#8217;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; add_submenu_page<span class="br0">&#40;</span><span class="st0">&#8216;options-general.php&#8217;</span>, <span class="st0">&#8216;myWeather&#8217;</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&#8216;myWeather&#8217;</span>, <span class="nu0">10</span>, <a href="http://www.php.net/basename"><span class="kw3">basename</span></a><span class="br0">&#40;</span><span class="kw2">__FILE__</span><span class="br0">&#41;</span>,<span class="st0">&#8216;myweather_admin&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p><a href="http://sharethis.com/item?&wp=2.5.1&amp;publisher=94167405-13d5-4f0e-b754-1ab80e6262f2&amp;title=myWeather+widget&amp;url=http%3A%2F%2Fwww.erata.net%2Fprogramming%2Fmyweather-widget%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.erata.net/programming/myweather-widget/feed/</wfw:commentRss>
		</item>
		<item>
		<title>qmake error:  sible braces mismatch %s:%d</title>
		<link>http://www.erata.net/qt-boost/qmake-error-sible-braces-mismatch-sd/</link>
		<comments>http://www.erata.net/qt-boost/qmake-error-sible-braces-mismatch-sd/#comments</comments>
		<pubDate>Fri, 27 Jul 2007 13:22:40 +0000</pubDate>
		<dc:creator>eti</dc:creator>
		
		<category><![CDATA[Qt &amp; boost]]></category>

		<category><![CDATA[error]]></category>

		<category><![CDATA[kdevelop]]></category>

		<category><![CDATA[qmake]]></category>

		<category><![CDATA[unix]]></category>

		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.erata.net/weblog/qt-boost/2007/07/27/qmake-error-sible-braces-mismatch-sd/</guid>
		<description><![CDATA[<p>
I&#8217;ve just received this error with qmake on windows. Googling for it showed no results so after i&#8217;ve solved the problem i decided to put it here.<br />
</p>
<p>The error was near a conditional block like:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&#160;</div>
</li>
<li class="li1">
<div class="de1">unix{</div>
</li>
<li class="li1">
<div class="de1">}</div>
</li>
<li class="li1">
<div class="de1">win32{</div>
</li>
<li class="li2">
<div class="de2">&#160; QMAKE_UIC+ = -L ../bin/plugin</div>
</li>
<li class="li1">
<div class="de1">}</div>
</li>
<li class="li1">
<div class="de1">&#160;</div>
</li>
</ol>
</div>
<p>
&#8230;after searching for&#8230;</p><script type="text/javascript">SHARETHIS.addEntry({ title: "qmake error:  sible braces mismatch %s:%d", url: "http://www.erata.net/qt-boost/qmake-error-sible-braces-mismatch-sd/" });</script>]]></description>
			<content:encoded><![CDATA[<p>
I&#8217;ve just received this error with qmake on windows. Googling for it showed no results so after i&#8217;ve solved the problem i decided to put it here.<br />
<span id="more-34"></span></p>
<p>The error was near a conditional block like:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">unix{</div>
</li>
<li class="li1">
<div class="de1">}</div>
</li>
<li class="li1">
<div class="de1">win32{</div>
</li>
<li class="li2">
<div class="de2">&nbsp; QMAKE_UIC+ = -L ../bin/plugin</div>
</li>
<li class="li1">
<div class="de1">}</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>
&#8230;after searching for unclosed/missing braces for a while without any result and comparing svn versions i&#8217;ve finally found the problem. On the QMAKE_UIC linke instead of &#8220;+=&#8221; somehow ( probably kdevelop&#8217;s qmake parser/generator ) got saved as &#8220;+ =&#8221; (notice the space). The problem would have been much easier to solve if the error message wasn&#8217;t so misleading.
</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">#bad version</div>
</li>
<li class="li1">
<div class="de1">QMAKE_UIC + = -L ../bin/plugin</div>
</li>
<li class="li1">
<div class="de1">#good version</div>
</li>
<li class="li2">
<div class="de2">QMAKE_UIC += -L ../bin/plugin</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>
So if you see this error look for operators that might have a space inserted in the middle. Hope this will save somebody&#8217;s time.</p>
<p><a href="http://sharethis.com/item?&wp=2.5.1&amp;publisher=94167405-13d5-4f0e-b754-1ab80e6262f2&amp;title=qmake+error%3A++sible+braces+mismatch+%25s%3A%25d&amp;url=http%3A%2F%2Fwww.erata.net%2Fqt-boost%2Fqmake-error-sible-braces-mismatch-sd%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.erata.net/qt-boost/qmake-error-sible-braces-mismatch-sd/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ASP.NET 2.0 and SQLServer 2000 Transactions</title>
		<link>http://www.erata.net/programming/aspnet-20-sqlserver-2000-transactions/</link>
		<comments>http://www.erata.net/programming/aspnet-20-sqlserver-2000-transactions/#comments</comments>
		<pubDate>Wed, 27 Jun 2007 09:21:11 +0000</pubDate>
		<dc:creator>eti</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[class]]></category>

		<category><![CDATA[datasets]]></category>

		<category><![CDATA[error]]></category>

		<category><![CDATA[public]]></category>

		<category><![CDATA[solution]]></category>

		<category><![CDATA[sql]]></category>

		<category><![CDATA[sqlserver]]></category>

		<category><![CDATA[transaction]]></category>

		<category><![CDATA[transactions]]></category>

		<category><![CDATA[type]]></category>

		<guid isPermaLink="false">http://www.erata.net/weblog/programming/2007/06/27/aspnet-20-sqlserver-2000-transactions/</guid>
		<description><![CDATA[<p>The new ADO.NET 2.0 and it&#8217;s typed datasets and table adapters are very useful tools for creating a DAL in you application. Still when working with SQLServer 2000 implementing transactions is a bit tricky.  You can use TransactionScope but is&#8230;</p><script type="text/javascript">SHARETHIS.addEntry({ title: "ASP.NET 2.0 and SQLServer 2000 Transactions", url: "http://www.erata.net/programming/aspnet-20-sqlserver-2000-transactions/" });</script>]]></description>
			<content:encoded><![CDATA[<p>The new ADO.NET 2.0 and it&#8217;s typed datasets and table adapters are very useful tools for creating a DAL in you application. Still when working with SQLServer 2000 implementing transactions is a bit tricky. <span id="more-30"></span> You can use TransactionScope but is seems to be designed for SQLServer 2005 as it will promote all transactions to distributed on SQLServer 2000 witch is a performance problem but also a bigger problem if your hosting provider does not provide distributed transactions. I&#8217;ve found a few solutions on the net some using reflection some using partial classes to add a method to the table adapter. Since i don&#8217;t like using reflection unless i absolutely have to I&#8217;ve come up with a solution using partial classes but trying to minimize the code you have to write for each table adapter and also trying to make is less error prone.<br />
First we define an interface witch the table adapters will implement:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">public</span> <span class="kw4">interface</span> ITransactionable</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; SqlConnection SqlConnection <span class="br0">&#123;</span>get;set;<span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; SqlCommand<span class="br0">&#91;</span><span class="br0">&#93;</span> Commands <span class="br0">&#123;</span>get;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>Now define a helper class that will manage all transaction operations.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">public</span> <span class="kw4">class</span> TransactionHelper</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">static</span> SqlTransaction BeginTransaction<span class="br0">&#40;</span>ITransactionable adapter<span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> BeginTransaction<span class="br0">&#40;</span>adapter,IsolationLevel.<span class="me1">ReadUncommitted</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">static</span> SqlTransaction BeginTransaction<span class="br0">&#40;</span>ITransactionable adapter, IsolationLevel lvl<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; SqlConnection con = adapter.<span class="me1">SqlConnection</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>con.<span class="me1">State</span> == ConnectionState.<span class="me1">Closed</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; con.<span class="me1">Open</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; SqlTransaction trans = con.<span class="me1">BeginTransaction</span><span class="br0">&#40;</span>lvl<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; SetTransaction<span class="br0">&#40;</span>adapter, trans<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> trans;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">static</span> <span class="kw1">void</span> SetTransaction<span class="br0">&#40;</span>ITransactionable adapter, SqlTransaction trans<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">foreach</span> <span class="br0">&#40;</span>SqlCommand com <span class="kw1">in</span> adapter.<span class="me1">Commands</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; com.<span class="me1">Transaction</span> = trans;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; adapter.<span class="me1">SqlConnection</span> = trans.<span class="me1">Connection</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>Now for each table adapter that we need to use transactions:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">public</span> partial <span class="kw4">class</span> DemoTableAdapter : ITransactionable</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">public</span> SqlConnection SqlConnection <span class="br0">&#123;</span> </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;get <span class="br0">&#123;</span> <span class="kw1">return</span> Connection; <span class="br0">&#125;</span> set <span class="br0">&#123;</span> Connection = value; <span class="br0">&#125;</span> <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">public</span> SqlCommand<span class="br0">&#91;</span><span class="br0">&#93;</span> Commands <span class="br0">&#123;</span> get <span class="br0">&#123;</span> <span class="kw1">return</span> CommandCollection; <span class="br0">&#125;</span> <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>As you can see the code needed for each table adapter is minimal and only requires copy-pasting and changing the name of the class. If c# would support c-style macros this could be reduced to a single line of code. To use the TransactionHelper class:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&#8230;.</div>
</li>
<li class="li1">
<div class="de1"><span class="me1">SqlTransaction</span> transaction=<span class="kw1">null</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">try</span><span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">using</span><span class="br0">&#40;</span>DemoTableAdapter adapter = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> DemoTableAdapter<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; transaction = TransactionHelper.<span class="me1">BeginTransaction</span><span class="br0">&#40;</span>adapter<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8230;. <span class="me1">operations</span> with adapter &#8230;.</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">using</span><span class="br0">&#40;</span>OtherTableAdapter adapter = <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span class="kw3">new</span></a> OtherTableAdapter <span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TransactionHelper.<span class="me1">SetTransaction</span><span class="br0">&#40;</span>adapter,transaction<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8230;. <span class="me1">operations</span> with adapter &#8230;.</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; transaction.<span class="me1">Commit</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">catch</span><span class="br0">&#40;</span>Exception x<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; transaction.<span class="me1">Rollback</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &#8230;<span class="me1">handle</span> error&#8230;.</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">finally</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">transaction.<span class="me1">Dispose</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
</ol>
</div>
<p>Hope it helps.</p>
<p><a href="http://sharethis.com/item?&wp=2.5.1&amp;publisher=94167405-13d5-4f0e-b754-1ab80e6262f2&amp;title=ASP.NET+2.0+and+SQLServer+2000+Transactions&amp;url=http%3A%2F%2Fwww.erata.net%2Fprogramming%2Faspnet-20-sqlserver-2000-transactions%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.erata.net/programming/aspnet-20-sqlserver-2000-transactions/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Windows Integration</title>
		<link>http://www.erata.net/freebsd/windows-integration/</link>
		<comments>http://www.erata.net/freebsd/windows-integration/#comments</comments>
		<pubDate>Fri, 18 May 2007 10:05:06 +0000</pubDate>
		<dc:creator>eti</dc:creator>
		
		<category><![CDATA[FreeBSD]]></category>

		<category><![CDATA[integration]]></category>

		<category><![CDATA[rdesktop]]></category>

		<category><![CDATA[window]]></category>

		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.erata.net/weblog/freebsd/2007/05/18/windows-integration/</guid>
		<description><![CDATA[Preview of my FreeBSD laptop<script type="text/javascript">SHARETHIS.addEntry({ title: "Windows Integration", url: "http://www.erata.net/freebsd/windows-integration/" });</script>]]></description>
			<content:encoded><![CDATA[<p>Here is a preview of what you can do if you have a windows machine somewhere.<br/><br />
<a href="http://www.erata.net/wp-content/uploads/Image/mydesktop.png" title="My Desktop"><br />
<img src="http://www.erata.net/wp-content/uploads/Image/mydesktop.png" alt="My Desktop" /></a></p>
<p><a href="http://sharethis.com/item?&wp=2.5.1&amp;publisher=94167405-13d5-4f0e-b754-1ab80e6262f2&amp;title=Windows+Integration&amp;url=http%3A%2F%2Fwww.erata.net%2Ffreebsd%2Fwindows-integration%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.erata.net/freebsd/windows-integration/feed/</wfw:commentRss>
		</item>
		<item>
		<title>[Update]Flash7 with native FreeBSD browsers</title>
		<link>http://www.erata.net/freebsd/updateflash7-with-native-freebsd-browsers/</link>
		<comments>http://www.erata.net/freebsd/updateflash7-with-native-freebsd-browsers/#comments</comments>
		<pubDate>Sun, 18 Mar 2007 11:11:03 +0000</pubDate>
		<dc:creator>eti</dc:creator>
		
		<category><![CDATA[FreeBSD]]></category>

		<category><![CDATA[bsd]]></category>

		<category><![CDATA[flash]]></category>

		<category><![CDATA[flash7]]></category>

		<category><![CDATA[flash9]]></category>

		<category><![CDATA[install]]></category>

		<category><![CDATA[ports]]></category>

		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.erata.net/weblog/freebsd/2007/03/18/updateflash7-with-native-freebsd-browsers/</guid>
		<description><![CDATA[<p>Finally the linux-flash7 plugin works with native firefox. If it&#8217;s not working for you this may help.</p>
<p></p>
<h2>Update</h2>
<p>With the nspluginwrapper port this <a href="http://unix.derkeiler.com/Mailing-Lists/FreeBSD/questions/2007-07/msg01919.htm"><br />
post</a> may be more usefull. The if you still have problems you may try the tips below.</p>
<h2>Step By Step HOWTO</h2>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&#160;</div>
</li>
<li class="li1">
<div class="de1">1.&#8230;</div></li></ol></div><script type="text/javascript">SHARETHIS.addEntry({ title: "[Update]Flash7 with native FreeBSD browsers", url: "http://www.erata.net/freebsd/updateflash7-with-native-freebsd-browsers/" });</script>]]></description>
			<content:encoded><![CDATA[<p>Finally the linux-flash7 plugin works with native firefox. If it&#8217;s not working for you this may help.</p>
<p><span id="more-28"></span></p>
<h2>Update</h2>
<p>With the nspluginwrapper port this <a href="http://unix.derkeiler.com/Mailing-Lists/FreeBSD/questions/2007-07/msg01919.htm"><br />
post</a> may be more usefull. The if you still have problems you may try the tips below.</p>
<h2>Step By Step HOWTO</h2>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">1. Use cvsup or portsnap to update your ports tree
</div>
</li>
<li class="li1">
<div class="de1">2. install www/linuxpluginwrapper
</div>
</li>
<li class="li1">
<div class="de1">3. copy libflashplayer.so and flashplayer.xpt from distfiles/flashplugin/7.0r68/install_flash_player_7_linux.tar.gz to /usr/local/lib/browser_plugins
</div>
</li>
<li class="li2">
<div class="de2">4. Fireup firefox or opera and test
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>
If in the future the dependency on the linux emulation layer is removed from linux-flash7 port it will be ok to install the port as you would normally do, but until then i prefer to manually unpack the two files instead of installing the hole linux-base port(s) witch is not needed anyway for the plugin to work.<br/><br />
If it works congratulations, if firefox crashes and opera displays just an empty box &#8230; read on.</p>
<h2>Fixing Plugin Crash</h2>
<p>Here there are two things to try. (the first one is recommended)</p>
<ol>
<li>edit /etc/X11/xorg.conf and <strong>disable the Composite extension</strong> and  <strong>set the ColorDepth to 24</strong></li>
<li>edit /usr/local/bin/firefox and add <strong>export XLIB_SKIP_ARGB_VISUALS=1</strong> in the beginning of the file</li>
</ol>
<p>I&#8217;ve noticed that opera still has some trouble working with the plugin and as a fix I&#8217;ve done a small change to the linuxpluginwrapper port. In compat_linux/linux_ioctl.c I&#8217;ve changed the default switch branch from:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">default</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; errno = ENOSYS;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; ret &nbsp; = <span class="nu0">-1</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; dprintf<span class="br0">&#40;</span><span class="st0">&quot;ioctl(fd=%d, request=%08X(on Linux), &#8230;) = %d / ERRNO = %d&quot;</span>, d, l_request, ret, errno<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">break</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>to</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">default</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;ret= _ioctl<span class="br0">&#40;</span>d,l_request,va_arg<span class="br0">&#40;</span>ap,<span class="kw4">int</span>*<span class="br0">&#41;</span><span class="br0">&#41;</span>; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="kw2">break</span>; </div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
</ol>
</div>
<p>After this change the plugin works fine but sometimes you need to reload the page for opera to display the flash content.</p>
<h2>References</h2>
<p>Information on fixing the crash was gathered from:</p>
<ul>
<li><a href="https://launchpad.net/ubuntu/+source/flashplugin-nonfree/+bug/62988">https://launchpad.net/ubuntu/+source/flashplugin-nonfree/+bug/62988</a></li>
<li><a href="http://www.kaourantin.net/#116224299860645174">http://www.kaourantin.net/#116224299860645174</a></li>
</ul>
<h2>To be continued</h2>
<p>Now that I&#8217;ve learned this i really have a good feeling about linux-flash9 and native browsers. I haven&#8217;t tested yet but i guess the fix for the crashes works also for linux-flash9 with linu-firefox and linux-opera.</p>
<p><a href="http://sharethis.com/item?&wp=2.5.1&amp;publisher=94167405-13d5-4f0e-b754-1ab80e6262f2&amp;title=%5BUpdate%5DFlash7+with+native+FreeBSD+browsers&amp;url=http%3A%2F%2Fwww.erata.net%2Ffreebsd%2Fupdateflash7-with-native-freebsd-browsers%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.erata.net/freebsd/updateflash7-with-native-freebsd-browsers/feed/</wfw:commentRss>
		</item>
		<item>
		<title>KDevelop - KDevTrollProject Problem</title>
		<link>http://www.erata.net/freebsd/kdevelop-kdevtrollproject-problem/</link>
		<comments>http://www.erata.net/freebsd/kdevelop-kdevtrollproject-problem/#comments</comments>
		<pubDate>Sat, 17 Mar 2007 10:17:23 +0000</pubDate>
		<dc:creator>eti</dc:creator>
		
		<category><![CDATA[FreeBSD]]></category>

		<category><![CDATA[bsd]]></category>

		<category><![CDATA[error]]></category>

		<category><![CDATA[kdevelop]]></category>

		<category><![CDATA[ping]]></category>

		<category><![CDATA[ports]]></category>

		<guid isPermaLink="false">http://www.erata.net/weblog/freebsd/2007/03/17/kdevelop-kdevtrollproject-problem/</guid>
		<description><![CDATA[<p>After updating kde to 3.5.6 and kdevelop to 3.4.0_1 ( around 15.03.2007 ) kdevelop failed to open qmake based projects. The error was &#8220;Error creating project management plugin KDevTrollProject&#8221;.</p>
<h2>Update</h2>
<p>On 23.03.2007 a fix has been committed to the kdevelop port so&#8230;</p><script type="text/javascript">SHARETHIS.addEntry({ title: "KDevelop - KDevTrollProject Problem", url: "http://www.erata.net/freebsd/kdevelop-kdevtrollproject-problem/" });</script>]]></description>
			<content:encoded><![CDATA[<p>After updating kde to 3.5.6 and kdevelop to 3.4.0_1 ( around 15.03.2007 ) kdevelop failed to open qmake based projects. The error was &#8220;Error creating project management plugin KDevTrollProject&#8221;.<span id="more-27"></span></p>
<h2>Update</h2>
<p>On 23.03.2007 a fix has been committed to the kdevelop port so if you encounter this problem it&#8217;s better to update the ports tree and recompile kdevelop.</p>
<h2>Finding why</h2>
<p>It took me a few houers to find out that the problem was an undefined reference to a symbol in <em>/usr/local/lib/libkdevqmakeparser.so</em>. The symbol was QMake::Lexer. Grepping to kdevelop sources i found that the libkdevqmakeparser is build in buildtools/lib/parsers/qmake. There i found that qmake_lex.cpp was not compiled and linked to the library.</p>
<h2>Quick Fix</h2>
<p>Below are the command lines to build qmake_lex.cpp and relink libkdevqmakeparser.so</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">#cd /usr/ports/devel/kdevelop</div>
</li>
<li class="li1">
<div class="de1">#make extract patch configure</div>
</li>
<li class="li1">
<div class="de1">#cd work/kdevelop-3.4.0/buildtools/lib/parsers/qmake</div>
</li>
<li class="li2">
<div class="de2">#fetch http://www.erata.net/wp-content/uploads/File/fix_lex.sh</div>
</li>
<li class="li1">
<div class="de1">#cat fix_lex.sh &nbsp;( just to make sure i haven&#8217;t hidden anything in that file <img src='http://www.erata.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> )</div>
</li>
<li class="li1">
<div class="de1">#sh fix_lex.sh</div>
</li>
<li class="li1">
<div class="de1">#cp .libs/libkdevqmakeparser.so.0 /usr/local/lib/</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<h2>Conclusion</h2>
<p>I somehow have the impression that I&#8217;m the only one having this problem since i haven&#8217;t seen any reports on the mailing lists. It may be some bad combination of autotools/libtools. If I&#8217;m the only one having this problem then it&#8217;s not worth investing more time in a proper fix. If other users will report this problem then probably a patch to add the qmake_lex.cpp file to the Makefile with appropriate rules may be needed. My experience with autotools and handwritten Makefiles is close to zero (and i intend to keep it that way) but i guess the kde folks will have no problem fixing this once the problem i known.</p>
<p>If someone else experiences this problem please leave a comment or a post a message on the freebsd mailing list</p>
<p><a href="http://sharethis.com/item?&wp=2.5.1&amp;publisher=94167405-13d5-4f0e-b754-1ab80e6262f2&amp;title=KDevelop+-+KDevTrollProject+Problem&amp;url=http%3A%2F%2Fwww.erata.net%2Ffreebsd%2Fkdevelop-kdevtrollproject-problem%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.erata.net/freebsd/kdevelop-kdevtrollproject-problem/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Virtual Destructors</title>
		<link>http://www.erata.net/programming/virtual-destructors/</link>
		<comments>http://www.erata.net/programming/virtual-destructors/#comments</comments>
		<pubDate>Sat, 18 Nov 2006 12:17:23 +0000</pubDate>
		<dc:creator>eti</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[c++]]></category>

		<category><![CDATA[class]]></category>

		<category><![CDATA[destructor]]></category>

		<category><![CDATA[destructors]]></category>

		<category><![CDATA[member]]></category>

		<category><![CDATA[private]]></category>

		<category><![CDATA[protected]]></category>

		<category><![CDATA[public]]></category>

		<category><![CDATA[qt]]></category>

		<category><![CDATA[safe]]></category>

		<category><![CDATA[type]]></category>

		<category><![CDATA[virtual]]></category>

		<guid isPermaLink="false">http://www.erata.net/weblog/programming/2006/11/18/virtual-destructors/</guid>
		<description><![CDATA[<h2>When do you need to declare a destructor virtual?</h2>
<p>Recently I’ve been involved in a thread on qt-interest mailing list about virtual destructors. A few people there suggested that you should always make the destructor of your class virtual. I strongly&#8230;</p><script type="text/javascript">SHARETHIS.addEntry({ title: "Virtual Destructors", url: "http://www.erata.net/programming/virtual-destructors/" });</script>]]></description>
			<content:encoded><![CDATA[<h2>When do you need to declare a destructor virtual?</h2>
<p>Recently I’ve been involved in a thread on qt-interest mailing list about virtual destructors. A few people there suggested that you should always make the destructor of your class virtual. I strongly disagree. </p>
<p><span id="more-26"></span></p>
<p>The argument was that if you use the virtual keyword on your destructor you will always be on the safe side. If someone inherits from your class and then deletes one of his instances of the class by a pointer to your base class you are sure his destructor gets called. So you are designing a class with value semantics (can be copied, can be assigned to) and you fear that someone will eventually inherit from your class so you make the destructor virtual. Well then why not make all the methods virtual so that if someone will inherit your class will have the possibility to customize its behavior. Is this starting to sound wrong? Well it should. </p>
<p>Just to be clear, I’m not trying to say that declaring a destructor virtual on a class WILL cause trouble. I’ll try to explain why it’s BAD CODING STYLE to always declare you destructor virtual. A good coding style will most probably keep you away from dangers like inheriting a class that has not been meant to be used as a base class.</p>
<p>As Herb Sutter and Andrei Alexandrescu state in “C++ Coding Standards: 101 Rules, Guidelines, and Best Practices” item 32:</p>
<p><strong>Be clear what kind of class you&#8217;re writing</strong></p>
<p>Be clear to yourself and to the users of your class. The most used types of classes are value classes and polymorphic classes. As a rule of thumb:</p>
<p><strong>Never try to write a class that is of both types.</strong></p>
<p>These types of classes are complementary. Value types are concrete types that mimic the built-in types, which are usually instantiated on the stack and are passed around by reference or by value. Polymorphic classes are meant to be used as base classes, are usually instantiated on the heap and used via (smart) pointer. In C++ the keyword virtual means “this will be a polymorphic class” and a copy constructor and assignment operator mean “this will be a value class”.</p>
<h2>Now when the destructor should be declared virtual?</h2>
<p>You <strong>MUST</strong> declare the destructor virtual <strong>ONLY</strong> if you are creating a polymorphic class witch has a <strong>PUBLIC</strong> destructor. That’s it. That’s the only case when you must declare the destructor virtual. If you don’t declare it virtual BAD THINGS will happen (destructors of child classes will not be called when deleting by base class).</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">struct</span> A <span class="br0">&#123;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; ~A<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">cout</span> &lt;&lt; <span class="st0">&quot; calling ~A()&quot;</span>; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">struct</span> B: <span class="kw2">public</span> A <span class="br0">&#123;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; ~B<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">cout</span> &lt;&lt; “~B<span class="br0">&#40;</span><span class="br0">&#41;</span>”;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> main<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; A* a = <span class="kw3">new</span> B;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">delete</span> a; <span class="co1">///In this case ~B() will not be called.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>You <strong>SHULD</strong> (read <strong>MUST</strong>) <strong>NOT</strong> declare your destructor virtual in any other case. If you declare it virtual the biggest problem is someone using your class might think that your class is a polymorphic class that can be inherited from. If this happens the code will probably work but will be awkward and difficult to write and maintain. There is also a performance hit that comes with virtual destructors but unless you are writing something where every nanosecond counts you will not care about this hit.</p>
<p>Now what do you do if you find a nice class that is a value class (even if the author made the destructor virtual) but you want to add some custom functionality to it?</p>
<p>Use <strong>FREE FUNCTIONS</strong>. That’s it. Having free functions will not make your coding less Object Oriented. Free function will give you the same access level as inheriting from a value class as value classes don’t usually have protected methods. To avoid problems place the free functions in the same namespace as the class. As an example if you have a string class and want to have a method that will return the word count from the string: </p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> wordCount<span class="br0">&#40;</span> <span class="kw4">const</span> string&amp; str <span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">///count the words</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> count;</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">void</span> doSomething<span class="br0">&#40;</span><span class="kw4">const</span> string&amp; str<span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// instead of str.wordCount() you will now have:</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">int</span> count = wordCount<span class="br0">&#40;</span>str<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>There are lots of things to be said about class design. You should search for books written on the subject and learn about good ways of creating classes. The sad part is that until you are bitten by a bad design that you have to live with you most probably will not understand the importance of good design and coding style in general.</p>
<p>In the end if you are an employer and want to quickly see if a candidate knows about virtual functions ask him what “static virtual functions” and “virtual constructors” have in common. ( if you don’t know the answer contact me <img src='http://www.erata.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ).</p>
<h2>Updates</h2>
<p>A very good article about <a href="http://www.gotw.ca/publications/mill18.htm" rel="external nofollow">virtuality</a></p>
<p>And another great article about <a href="http://www.ddj.com/dept/cpp/184403760" rel="external nofollow">virtual functions</a></p>
<p>
<quote>&#8220;Virtual functions should be treated very much like data members — make them private, until design needs indicate a less restricted approach is indicated. It is much easier to promote them to a more accessible level, than it is to demote them to a more private level.&#8221;</quote></p>
<p><a href="http://sharethis.com/item?&wp=2.5.1&amp;publisher=94167405-13d5-4f0e-b754-1ab80e6262f2&amp;title=Virtual+Destructors&amp;url=http%3A%2F%2Fwww.erata.net%2Fprogramming%2Fvirtual-destructors%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.erata.net/programming/virtual-destructors/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Qt4 Synchronous HTTP Request</title>
		<link>http://www.erata.net/qt-boost/synchronous-http-request/</link>
		<comments>http://www.erata.net/qt-boost/synchronous-http-request/#comments</comments>
		<pubDate>Wed, 08 Nov 2006 16:13:00 +0000</pubDate>
		<dc:creator>eti</dc:creator>
		
		<category><![CDATA[Qt &amp; boost]]></category>

		<category><![CDATA[class]]></category>

		<category><![CDATA[error]]></category>

		<category><![CDATA[http]]></category>

		<category><![CDATA[ping]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[protected]]></category>

		<category><![CDATA[public]]></category>

		<category><![CDATA[qt]]></category>

		<category><![CDATA[solution]]></category>

		<category><![CDATA[virtual]]></category>

		<guid isPermaLink="false">http://www.erata.net/weblog/qt-boost/2006/11/08/synchronous-http-request/</guid>
		<description><![CDATA[<h2>Problem</h2>
<p>Creating a wrapper over QHttp that can perform GET and POST requests  in a synchronous way.</p>
<p></p>
<h2>Solution</h2>
<p>In Qt4 QHttp can perform HTTP requests, but the API only allows asynchronous  requests. This means that you need to specify a set of&#160;slots to&#8230;</p><script type="text/javascript">SHARETHIS.addEntry({ title: "Qt4 Synchronous HTTP Request", url: "http://www.erata.net/qt-boost/synchronous-http-request/" });</script>]]></description>
			<content:encoded><![CDATA[<h2>Problem</h2>
<p>Creating a wrapper over QHttp that can perform GET and POST requests  in a synchronous way.</p>
<p><span id="more-25"></span></p>
<h2>Solution</h2>
<p>In Qt4 QHttp can perform HTTP requests, but the API only allows asynchronous  requests. This means that you need to specify a set of&nbsp;slots to handle the  signals that can be emitted while the request if performed. Now don&#8217;t get me  wrong, this is event driven programming  and most of the times is the right way  to go especially when writing a Qt based application.&nbsp; The cases when  event driven operations prove difficult to use are rare and usually can be programmed  using events. <br />
  Recently I&rsquo;ve developed a small application that had to do a number of  requests in a specified order and show a message if an error was to occur. The  algorithm was simple:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">foreach</span> <span class="br0">&#40;</span> Request r , requestList <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>! runRequest<span class="br0">&#40;</span>r<span class="br0">&#41;</span> <span class="br0">&#41;</span> <span class="kw1">return</span> error;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>For writing something like this I would like to not split the algorithm across  a set of slots. So I would like to have a possibility to run a request and wait  for it to finish.</p>
<h2>Implementation</h2>
<p>We start by creating a <em>SyncHTTP</em> class that is derived from QHttp:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">class</span> SyncHTTP: <span class="kw2">public</span> <a href="http://doc.trolltech.com/4.2/QHttp.html"><span class="kw5">QHttp</span></a><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">Q_OBJECT</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// id of current request</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw4">int</span> requestID;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// error status of current request</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">bool</span> status;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// event loop used to block until request finished</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <a href="http://doc.trolltech.com/4.2/QEventLoop.html"><span class="kw5">QEventLoop</span></a> loop; </div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">public</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// structors</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; SyncHTTP<span class="br0">&#40;</span> <a href="http://doc.trolltech.com/4.2/QObject.html"><span class="kw5">QObject</span></a> * parent = <span class="nu0">0</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; :<a href="http://doc.trolltech.com/4.2/QHttp.html"><span class="kw5">QHttp</span></a><span class="br0">&#40;</span>parent<span class="br0">&#41;</span>,requestID<span class="br0">&#40;</span><span class="nu0">-1</span><span class="br0">&#41;</span>,status<span class="br0">&#40;</span><span class="kw2">false</span><span class="br0">&#41;</span><span class="br0">&#123;</span><span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; SyncHTTP<span class="br0">&#40;</span> <span class="kw4">const</span> <a href="http://doc.trolltech.com/4.2/QString.html"><span class="kw5">QString</span></a> &amp; hostName,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; quint16 port = <span class="nu0">80</span>, <a href="http://doc.trolltech.com/4.2/QObject.html"><span class="kw5">QObject</span></a> * parent = <span class="nu0">0</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; :<a href="http://doc.trolltech.com/4.2/QHttp.html"><span class="kw5">QHttp</span></a><span class="br0">&#40;</span>hostName,port,parent<span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; requestID<span class="br0">&#40;</span><span class="nu0">-1</span><span class="br0">&#41;</span>,status<span class="br0">&#40;</span><span class="kw2">false</span><span class="br0">&#41;</span><span class="br0">&#123;</span><span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">virtual</span> ~SyncHTTP<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Now we need to implement the methods for <em>syncGet</em> and <em>syncPost</em> to mimic the <em>get</em> and <em>post</em> methods from QHttp: </p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="co1">/// send GET request and wait until finished</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">bool</span> syncGet <span class="br0">&#40;</span> <span class="kw4">const</span> <a href="http://doc.trolltech.com/4.2/QString.html"><span class="kw5">QString</span></a> &amp; path, <a href="http://doc.trolltech.com/4.2/QIODevice.html"><span class="kw5">QIODevice</span></a> * to = <span class="nu0">0</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">///connect the requestFinished signal to our finished slot</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw2">connect</span><span class="br0">&#40;</span><span class="kw3">this</span>,<span class="kw4">SIGNAL</span><span class="br0">&#40;</span>requestFinished<span class="br0">&#40;</span><span class="kw4">int</span>,<span class="kw4">bool</span><span class="br0">&#41;</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; SLOT<span class="br0">&#40;</span>finished<span class="br0">&#40;</span><span class="kw4">int</span>,<span class="kw4">bool</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// start the request and store the requestID</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; requestID = get<span class="br0">&#40;</span>path, to <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// block until the request is finished</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; loop.<span class="me1">exec</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// return the request status</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> status;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">/// send POST request and wait until finished</span></div>
</li>
<li class="li2">
<div class="de2"><span class="kw4">bool</span> syncPost <span class="br0">&#40;</span> <span class="kw4">const</span> <a href="http://doc.trolltech.com/4.2/QString.html"><span class="kw5">QString</span></a> &amp; path, </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://doc.trolltech.com/4.2/QIODevice.html"><span class="kw5">QIODevice</span></a> * data, <a href="http://doc.trolltech.com/4.2/QIODevice.html"><span class="kw5">QIODevice</span></a> * to = <span class="nu0">0</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">///connect the requestFinished signal to our finished slot</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">connect</span><span class="br0">&#40;</span><span class="kw3">this</span>,<span class="kw4">SIGNAL</span><span class="br0">&#40;</span>requestFinished<span class="br0">&#40;</span><span class="kw4">int</span>,<span class="kw4">bool</span><span class="br0">&#41;</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; SLOT<span class="br0">&#40;</span>finished<span class="br0">&#40;</span><span class="kw4">int</span>,<span class="kw4">bool</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// start the request and store the requestID</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; requestID = post<span class="br0">&#40;</span>path, data , to <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// block until the request is finished</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; loop.<span class="me1">exec</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="co1">/// return the request status</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> status;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span> </div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">bool</span> syncPost <span class="br0">&#40;</span> <span class="kw4">const</span> <a href="http://doc.trolltech.com/4.2/QString.html"><span class="kw5">QString</span></a> &amp; path, </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">const</span> QByteArray&amp; data, <a href="http://doc.trolltech.com/4.2/QIODevice.html"><span class="kw5">QIODevice</span></a> * to = <span class="nu0">0</span> <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// create io device from QByteArray</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <a href="http://doc.trolltech.com/4.2/QBuffer.html"><span class="kw5">QBuffer</span></a> buffer;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; buffer.<span class="me1">setData</span><span class="br0">&#40;</span>data<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> syncPost<span class="br0">&#40;</span>path,&amp;buffer,to<span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p> The <em>syncGet</em> and <em>syncPost</em> functions both use the same strategy. They connect the <em>requestFinished</em> signal from QHttp to a <em>finished</em> slot, they ask the QHttp object to perform the request. The QHttp&#8217;s get/post method returns immediately with the request id that has been assigned to the current request. Now  the nice part: After asking the QHttp object to perform the request we need to wait for it to finish, so we create an event loop and start it. The main event loop is now blocked and we are nor risking being called aging while executing the request. The blocking code is not using tricks like sleep or infinite loops so we don&#8217;t end up using 100% CPU or wasting time sleeping. Now we just need to implement the <em>finished</em> slot to save the result and exit the loop: </p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">protected</span> <span class="kw2">slots</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">virtual</span> <span class="kw4">void</span> finished<span class="br0">&#40;</span><span class="kw4">int</span> idx, <span class="kw4">bool</span> err<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">/// check to see if it&#8217;s the request we made</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>idx!=requestID<span class="br0">&#41;</span> <span class="kw1">return</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">/// set status of the request</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; status = !err;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">/// end the loop</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; loop.<span class="kw3">exit</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>Now this slot first checks to see if it&#8217;s being called for our request and returns if not, after that saves the error status returned by the QHttp object and exits the loop. The execution now will return in the <em>syncGet/syncPost</em> function that will return the status to the caller. </p>
<h2>Testing</h2>
<p>Ok, let&#8217;s write a small test application. Writing real automated test cases for this kind of class is possible but not trivial so will just write a small test app.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co2">#include &lt;QApplication&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">#include &lt;QDebug&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">#include &quot;synchttp.h&quot;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw4">int</span> main<span class="br0">&#40;</span><span class="kw4">int</span> argc, <span class="kw4">char</span> *argv<span class="br0">&#91;</span><span class="br0">&#93;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <a href="http://doc.trolltech.com/4.2/QApplication.html"><span class="kw5">QApplication</span></a> a<span class="br0">&#40;</span>argc,argv<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// create object</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; SyncHTTP h<span class="br0">&#40;</span><span class="st0">&quot;www.google.com&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">///prepare output buffer</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <a href="http://doc.trolltech.com/4.2/QBuffer.html"><span class="kw5">QBuffer</span></a> getOutput;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; h.<span class="me1">syncGet</span><span class="br0">&#40;</span> <span class="st0">&quot;/search?q=erata.net&quot;</span>,&amp;getOutput <span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; qDebug<span class="br0">&#40;</span><span class="br0">&#41;</span> &lt; &lt; getOutput.<span class="me1">data</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <a href="http://doc.trolltech.com/4.2/QByteArray.html"><span class="kw5">QByteArray</span></a> data<span class="br0">&#40;</span><a href="http://doc.trolltech.com/4.2/QString.html"><span class="kw5">QString</span></a><span class="br0">&#40;</span><span class="st0">&quot;q=data&quot;</span><span class="br0">&#41;</span>.<span class="me1">toLatin1</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <a href="http://doc.trolltech.com/4.2/QBuffer.html"><span class="kw5">QBuffer</span></a> postOutput;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; h.<span class="me1">syncPost</span><span class="br0">&#40;</span> <span class="st0">&quot;/search&quot;</span>,data, &amp;postOutput<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; qDebug<span class="br0">&#40;</span><span class="br0">&#41;</span> &lt; &lt; postOutput.<span class="me1">data</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="nu0">0</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>Now in conclusion i would like to say that i recommend using this class only when you simply need to perform a request and know if it was successful or not. On any other case, where you need to do more complicated things learn to use Qt&#8217;s event driven programming model.</p>
<p>Download <a href="http://www.erata.net/wp-content/uploads/File/synchttp.h" title="Source File for SyncHTTP" rel="nofollow">synchttp.h</a> </p>
<p>PS: this is my first programming HOWTO so be merciful <img src='http://www.erata.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
<p><a href="http://sharethis.com/item?&wp=2.5.1&amp;publisher=94167405-13d5-4f0e-b754-1ab80e6262f2&amp;title=Qt4+Synchronous+HTTP+Request&amp;url=http%3A%2F%2Fwww.erata.net%2Fqt-boost%2Fsynchronous-http-request%2F">ShareThis</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.erata.net/qt-boost/synchronous-http-request/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
