title: Boost asio with Qt
body: <p>I am trying to use <a href="http://www.boost.org/doc/libs/1_36_0/doc/html/boost_asio/example/http/client/async_client.cpp" rel="nofollow noreferrer">boost::asio async client example</a> with a simple Qt GUI like:</p>
  
  <p><a href="https://i.stack.imgur.com/xxq9X.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xxq9X.png" alt="enter image description here"></a></p>
  
  <p>A little snippet from my app:</p>
  
  <p>The button click SLOT:</p>
  
  <pre><code>void RestWidget::restGetCall()
  {
  
      networkService ntwkSer("www.boost.org","80");
      connect(&amp;ntwkSer, SIGNAL(responseReady(std::string)), this, SLOT(showResponse(std::string)));
      ntwkSer.get("/LICENSE_1_0.txt");
  
  }
  </code></pre>
  
  <p>The networkService class is just a wrapper of the above linked boost sample code.Its derived from QObject class for signal,slot mechanism.</p>
  
  <pre><code>void networkService::get(const std::string &amp; path)
  {
     // boost::thread (boost::bind(&amp;networkService::networkCall,this,path));//this gives me sigabrt
      networkCall(path);//this works fine, and i get output as pictured above.
  }
  
  void networkService::networkCall(const std::string path)
  {
      tcp::resolver::query query(host_, port_);//also these host,port fields come out to be invalid/garbage.
      //tcp::resolver::query query("www.boost.org","80");//still doesnt resolve the SIGABRT
      resolver_.async_resolve(query,
          boost::bind(&amp;networkService::handle_resolve, this,
          boost::asio::placeholders::error,
          boost::asio::placeholders::iterator,
          path));
      io_service.run();
  }
  </code></pre>
  
  <p>The problem, is when i run the io_service.run() from the boost::thread. i get SIGABRT.</p>
  
  <p>also he host_,port_ networkService wrapper class fields inside the networkService::networkCall(path) function on debugging come out to be invalid, which get saved while constructing:</p>
  
  <pre><code>networkService ntwkSer("www.boost.org","80");
  </code></pre>
  
  <p>The obvious reason for boost::thread is to make GUI non-blocking,since io_service() has its own eventloop. My intention is to run boost::asio async calls in a seperate boost thread, and notify the GUI thread with QT's Q_OBJECT signal slot mechanism.</p>
  
  <p>I don't get the reason of SIGABRT and also why could the field values of host_ and port_ become invalid once i start using boost::thread.</p>
  
  <p>PS: This same setup, behaves correctly with boost::thread from a similar commandline application (no Qt GUI code), i.e when the networkService class is not hacked for Qt signal/slot to notify the main GUI thread. Here, i use the boost::asio's response from within the boost::thread.</p>
  
  <p>Edit:
  as per responses to my question, i tried this... i disabled Q_OBJECT signal/slot and QObject derivation of the networkservice class, to be sure MOC isnt messing things up.. but still, the issue prevails, i get access violation on windows vs sigabrt on linux. The issue of the networkservice object's fields getting corrupted is also present, eventually getting access violation.
  In effect no change in behaviour.</p>
  
  <p>before launching thread:
  <a href="https://i.stack.imgur.com/DlXN7.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DlXN7.jpg" alt="enter image description here"></a>
  from inside thread
  <a href="https://i.stack.imgur.com/GD2Pr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GD2Pr.png" alt="enter image description here"></a>
  access violation on continue...
  <a href="https://i.stack.imgur.com/prpqN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/prpqN.png" alt="enter image description here"></a></p>
  
  <p>So, even without MOC , the issue is still there.</p>
  
  <p>Edit 2:
  Im sorry for bothering.. i did a huge mistake, of using a local networkService object from within the boost::thread, which got scoped out when the thread actually ran! </p>