<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Qt4 Synchronous HTTP Request</title>
	<atom:link href="http://www.erata.net/qt-boost/synchronous-http-request/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.erata.net/qt-boost/synchronous-http-request/</link>
	<description>If we don't have the solution you have the wrong problem</description>
	<lastBuildDate>Wed, 28 Dec 2011 10:48:55 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Marc</title>
		<link>http://www.erata.net/qt-boost/synchronous-http-request/comment-page-1/#comment-4281</link>
		<dc:creator>Marc</dc:creator>
		<pubDate>Thu, 10 Feb 2011 22:43:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.erata.net/weblog/qt-boost/2006/11/08/synchronous-http-request/#comment-4281</guid>
		<description>Kudos for this...thanks!!</description>
		<content:encoded><![CDATA[<p>Kudos for this&#8230;thanks!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eti</title>
		<link>http://www.erata.net/qt-boost/synchronous-http-request/comment-page-1/#comment-3700</link>
		<dc:creator>eti</dc:creator>
		<pubDate>Fri, 26 Feb 2010 11:50:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.erata.net/weblog/qt-boost/2006/11/08/synchronous-http-request/#comment-3700</guid>
		<description>@Grzegorz 
It&#039;s been a while since I&#039;ve written this code, and at the moment i don&#039;t have access to a Qt installation so I&#039;m only guessing but:

I think that you can use the QHttp class to make more than one request at the same time, each having it&#039;s own request id and that&#039;s probably why trolltech designed the interface this way.

As for the &quot;bad&quot; responses i remember that i was curious about this at the time and that i discovered that the QHttp class can make other internal, protocol specific, requests witch are handled the same way as normal requests. I think that braking with a debugger when the &quot;bad&quot; response arrives will give you a clearer answer.</description>
		<content:encoded><![CDATA[<p>@Grzegorz<br />
It&#8217;s been a while since I&#8217;ve written this code, and at the moment i don&#8217;t have access to a Qt installation so I&#8217;m only guessing but:</p>
<p>I think that you can use the QHttp class to make more than one request at the same time, each having it&#8217;s own request id and that&#8217;s probably why trolltech designed the interface this way.</p>
<p>As for the &#8220;bad&#8221; responses i remember that i was curious about this at the time and that i discovered that the QHttp class can make other internal, protocol specific, requests witch are handled the same way as normal requests. I think that braking with a debugger when the &#8220;bad&#8221; response arrives will give you a clearer answer.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Grzegorz.W</title>
		<link>http://www.erata.net/qt-boost/synchronous-http-request/comment-page-1/#comment-3699</link>
		<dc:creator>Grzegorz.W</dc:creator>
		<pubDate>Fri, 26 Feb 2010 08:58:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.erata.net/weblog/qt-boost/2006/11/08/synchronous-http-request/#comment-3699</guid>
		<description>I have question about (IHMO) mysterious line that says
&#039;if(idx!=requestID) return;&#039;
How is it possible that the response could come with the Id other the was requested?
I&#039;m also using the syncHttp code and I&#039;ve noticed that when http request is done , it always assigns even number id&#039;s . &#039;requestFinished&#039; slot is fired twice, once for Id that is improper , and the second with one we want. 
Can anyone explain where do the &#039;bad&#039; reponses come from ?</description>
		<content:encoded><![CDATA[<p>I have question about (IHMO) mysterious line that says<br />
&#8216;if(idx!=requestID) return;&#8217;<br />
How is it possible that the response could come with the Id other the was requested?<br />
I&#8217;m also using the syncHttp code and I&#8217;ve noticed that when http request is done , it always assigns even number id&#8217;s . &#8216;requestFinished&#8217; slot is fired twice, once for Id that is improper , and the second with one we want.<br />
Can anyone explain where do the &#8216;bad&#8217; reponses come from ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yasir Hussain</title>
		<link>http://www.erata.net/qt-boost/synchronous-http-request/comment-page-1/#comment-3685</link>
		<dc:creator>Yasir Hussain</dc:creator>
		<pubDate>Sun, 17 Jan 2010 07:39:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.erata.net/weblog/qt-boost/2006/11/08/synchronous-http-request/#comment-3685</guid>
		<description>Thank you very much for this Excellent piece of concept.</description>
		<content:encoded><![CDATA[<p>Thank you very much for this Excellent piece of concept.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: C# HTTP Request &#124; Erata.NET</title>
		<link>http://www.erata.net/qt-boost/synchronous-http-request/comment-page-1/#comment-3654</link>
		<dc:creator>C# HTTP Request &#124; Erata.NET</dc:creator>
		<pubDate>Sat, 21 Nov 2009 10:06:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.erata.net/weblog/qt-boost/2006/11/08/synchronous-http-request/#comment-3654</guid>
		<description>[...] few years ago I’ve written an article on how to perform a synchronous HTTP request using Qt 4.2. I I’ve seen this article today and since now I’m mostly working [...]</description>
		<content:encoded><![CDATA[<p>[...] few years ago I’ve written an article on how to perform a synchronous HTTP request using Qt 4.2. I I’ve seen this article today and since now I’m mostly working [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: danipellex</title>
		<link>http://www.erata.net/qt-boost/synchronous-http-request/comment-page-1/#comment-3650</link>
		<dc:creator>danipellex</dc:creator>
		<pubDate>Fri, 16 Oct 2009 10:11:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.erata.net/weblog/qt-boost/2006/11/08/synchronous-http-request/#comment-3650</guid>
		<description>Excellent piece of code! 
really useful 2 years later!

best wishes for you and thank you very much
pellex</description>
		<content:encoded><![CDATA[<p>Excellent piece of code!<br />
really useful 2 years later!</p>
<p>best wishes for you and thank you very much<br />
pellex</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roberto</title>
		<link>http://www.erata.net/qt-boost/synchronous-http-request/comment-page-1/#comment-3640</link>
		<dc:creator>Roberto</dc:creator>
		<pubDate>Thu, 01 Oct 2009 14:28:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.erata.net/weblog/qt-boost/2006/11/08/synchronous-http-request/#comment-3640</guid>
		<description>GREAT!!! I can do synchronous Xmlrpc calls now!!!

Thanks a lot!!!!!</description>
		<content:encoded><![CDATA[<p>GREAT!!! I can do synchronous Xmlrpc calls now!!!</p>
<p>Thanks a lot!!!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eti</title>
		<link>http://www.erata.net/qt-boost/synchronous-http-request/comment-page-1/#comment-3491</link>
		<dc:creator>eti</dc:creator>
		<pubDate>Tue, 21 Oct 2008 08:19:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.erata.net/weblog/qt-boost/2006/11/08/synchronous-http-request/#comment-3491</guid>
		<description>Hi,
Glad to know this code was useful.</description>
		<content:encoded><![CDATA[<p>Hi,<br />
Glad to know this code was useful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Juan Navarro</title>
		<link>http://www.erata.net/qt-boost/synchronous-http-request/comment-page-1/#comment-3490</link>
		<dc:creator>Juan Navarro</dc:creator>
		<pubDate>Tue, 21 Oct 2008 08:14:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.erata.net/weblog/qt-boost/2006/11/08/synchronous-http-request/#comment-3490</guid>
		<description>Hi! I found your SyncHTTP class some months ago and have been using it since then, it&#039;s very useful thanks!
Today I have revisited this page to see if any updates to the code were available, and have seen the version I use is not exactly the same you have, but I don&#039;t remember (well my memory is sooo bad :D) if that is because I changed your code or because you have modified it from the original :)

Those changes are the two methods syncSetHost and syncSetUser, and the connect() calls are moved to the constructors (to avoid re-connecting the signals in each call to this class).

So the code is as follows:

/***************************************************************************
 *   Copyright (C) 2005 by Iulian M                                        *
 *   eti@erata.net                                                         *
 ***************************************************************************/
#ifndef ETKSYNCHTTP_H
#define ETKSYNCHTTP_H

#include 
#include 
#include 

/**
 * Provide a synchronous api over QHttp
 * Uses a QEventLoop to block until the request is completed
 * @author Iulian M 
*/
class SyncHTTP: public QHttp
{
	Q_OBJECT
	public:
		/// constructors
		SyncHTTP(QObject* parent=0)
			: QHttp(parent), requestID(-1), status(false)
		{
			///connect the requestFinished signal to our finished slot
			connect(this,SIGNAL(requestFinished(int,bool)),SLOT(finished(int,bool)));
		}

		SyncHTTP(const QString&amp; hostName, quint16 port=80, QObject* parent=0)
			: QHttp(hostName,port,parent), requestID(-1), status(false)
		{
			///connect the requestFinished signal to our finished slot
			connect(this,SIGNAL(requestFinished(int,bool)),SLOT(finished(int,bool)));
		}

		virtual ~SyncHTTP() {}

		/// send GET request and wait until finished
		bool syncGet(const QString&amp; path, QIODevice* to=0)
		{
			/// start the request and store the requestID
			requestID = get(path, to);
			/// block until the request is finished
			loop.exec();
			/// return the request status
			return status;
		}

		/// send POST request and wait until finished
		bool syncPost(const QString&amp; path, QIODevice* data, QIODevice* to=0)
		{
			/// start the request and store the requestID
			requestID = post(path, data, to);
			/// block until the request is finished
			loop.exec();
			/// return the request status
			return status;
		}

		bool syncPost(const QString&amp; path, const QByteArray&amp; data, QIODevice* to=0)
		{
			/// create io device from QByteArray
			QBuffer buffer;
			buffer.setData(data);
			return syncPost(path, &amp;buffer, to);
		}

		bool syncSetHost(const QString&amp; hostName, quint16 port=80)
		{
			/// start the request and store the requestID
			requestID = setHost(hostName, port);
			/// block until the request is finished
			loop.exec();
			/// return the request status
			return status;
		}

		bool syncSetUser(const QString&amp; userName, const QString&amp; password=QString())
		{
			/// start the request and store the requestID
			requestID = setUser(userName, password);
			/// block until the request is finished
			loop.exec();
			/// return the request status
			return status;
		}

	protected slots:
		virtual void finished(int idx, bool err)
		{
			/// check to see if it&#039;s the request we made
			if (idx != requestID)
				return;
			/// set status of the request
			status = !err;
			/// end the loop
			loop.exit();
		}

	private:
		/// id of current request
		int requestID;
		/// error status of current request
		bool status;
		/// event loop used to block until request finished
		QEventLoop loop;
};


#endif


goodbye!</description>
		<content:encoded><![CDATA[<p>Hi! I found your SyncHTTP class some months ago and have been using it since then, it&#8217;s very useful thanks!<br />
Today I have revisited this page to see if any updates to the code were available, and have seen the version I use is not exactly the same you have, but I don&#8217;t remember (well my memory is sooo bad <img src='http://www.erata.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> ) if that is because I changed your code or because you have modified it from the original <img src='http://www.erata.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Those changes are the two methods syncSetHost and syncSetUser, and the connect() calls are moved to the constructors (to avoid re-connecting the signals in each call to this class).</p>
<p>So the code is as follows:</p>
<p>/***************************************************************************<br />
 *   Copyright (C) 2005 by Iulian M                                        *<br />
 *   <a href="mailto:eti@erata.net">eti@erata.net</a>                                                         *<br />
 ***************************************************************************/<br />
#ifndef ETKSYNCHTTP_H<br />
#define ETKSYNCHTTP_H</p>
<p>#include<br />
#include<br />
#include </p>
<p>/**<br />
 * Provide a synchronous api over QHttp<br />
 * Uses a QEventLoop to block until the request is completed<br />
 * @author Iulian M<br />
*/<br />
class SyncHTTP: public QHttp<br />
{<br />
	Q_OBJECT<br />
	public:<br />
		/// constructors<br />
		SyncHTTP(QObject* parent=0)<br />
			: QHttp(parent), requestID(-1), status(false)<br />
		{<br />
			///connect the requestFinished signal to our finished slot<br />
			connect(this,SIGNAL(requestFinished(int,bool)),SLOT(finished(int,bool)));<br />
		}</p>
<p>		SyncHTTP(const QString&amp; hostName, quint16 port=80, QObject* parent=0)<br />
			: QHttp(hostName,port,parent), requestID(-1), status(false)<br />
		{<br />
			///connect the requestFinished signal to our finished slot<br />
			connect(this,SIGNAL(requestFinished(int,bool)),SLOT(finished(int,bool)));<br />
		}</p>
<p>		virtual ~SyncHTTP() {}</p>
<p>		/// send GET request and wait until finished<br />
		bool syncGet(const QString&amp; path, QIODevice* to=0)<br />
		{<br />
			/// start the request and store the requestID<br />
			requestID = get(path, to);<br />
			/// block until the request is finished<br />
			loop.exec();<br />
			/// return the request status<br />
			return status;<br />
		}</p>
<p>		/// send POST request and wait until finished<br />
		bool syncPost(const QString&amp; path, QIODevice* data, QIODevice* to=0)<br />
		{<br />
			/// start the request and store the requestID<br />
			requestID = post(path, data, to);<br />
			/// block until the request is finished<br />
			loop.exec();<br />
			/// return the request status<br />
			return status;<br />
		}</p>
<p>		bool syncPost(const QString&amp; path, const QByteArray&amp; data, QIODevice* to=0)<br />
		{<br />
			/// create io device from QByteArray<br />
			QBuffer buffer;<br />
			buffer.setData(data);<br />
			return syncPost(path, &amp;buffer, to);<br />
		}</p>
<p>		bool syncSetHost(const QString&amp; hostName, quint16 port=80)<br />
		{<br />
			/// start the request and store the requestID<br />
			requestID = setHost(hostName, port);<br />
			/// block until the request is finished<br />
			loop.exec();<br />
			/// return the request status<br />
			return status;<br />
		}</p>
<p>		bool syncSetUser(const QString&amp; userName, const QString&amp; password=QString())<br />
		{<br />
			/// start the request and store the requestID<br />
			requestID = setUser(userName, password);<br />
			/// block until the request is finished<br />
			loop.exec();<br />
			/// return the request status<br />
			return status;<br />
		}</p>
<p>	protected slots:<br />
		virtual void finished(int idx, bool err)<br />
		{<br />
			/// check to see if it&#8217;s the request we made<br />
			if (idx != requestID)<br />
				return;<br />
			/// set status of the request<br />
			status = !err;<br />
			/// end the loop<br />
			loop.exit();<br />
		}</p>
<p>	private:<br />
		/// id of current request<br />
		int requestID;<br />
		/// error status of current request<br />
		bool status;<br />
		/// event loop used to block until request finished<br />
		QEventLoop loop;<br />
};</p>
<p>#endif</p>
<p>goodbye!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abhi</title>
		<link>http://www.erata.net/qt-boost/synchronous-http-request/comment-page-1/#comment-40</link>
		<dc:creator>Abhi</dc:creator>
		<pubDate>Fri, 16 Feb 2007 20:25:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.erata.net/weblog/qt-boost/2006/11/08/synchronous-http-request/#comment-40</guid>
		<description>Awesome - piece of code
It is helpful - thanks a lot</description>
		<content:encoded><![CDATA[<p>Awesome &#8211; piece of code<br />
It is helpful &#8211; thanks a lot</p>
]]></content:encoded>
	</item>
</channel>
</rss>

