title: Connect to WebSocket server from Qt UI with Echo Client Example
body: <p>I'm using <a href="http://doc.qt.io/qt-5/qtwebsockets-echoserver-example.html" rel="nofollow">Websocket Echo Server Example</a> in CLI and it works fine. I'm trying to connect to this server from my Qt GUI project. I have MainWindow class with an appropriate slot</p>
  
  <pre><code>void MainWindow::on_pushButton_clicked()
  {
      qDebug() &lt;&lt; "Push btn clicked";
      EchoClient client(QUrl(QStringLiteral("ws://localhost:1234")));
  }
  </code></pre>
  
  <p>and EchoClient files from CLI <a href="http://doc.qt.io/qt-5/qtwebsockets-echoclient-example.html" rel="nofollow">Websocket Echo Client Example</a>.</p>
  
  <p>The main problem is that that I can't connect to the server when I push button on the form. However, I see debug message <em>"Push btn clicked"</em>. It is supposed to be printed "Hello, world!". But nothing happens, no errors. Even signal <code>void EchoClient::onConnected()</code> is not fired.</p>
  
  <p>But if I move <code>EchoClient client(QUrl(QStringLiteral("ws://localhost:1234")));</code> to main.cpp it connects: </p>
  
  <pre><code>int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
      MainWindow w;
      w.show();
      EchoClient client(QUrl(QStringLiteral("ws://localhost:1234")));
      return a.exec();
  }
  </code></pre>
  
  <p>I am completely new in C++ and Qt.
  Why this happens? Is it something with processing threads in UI? What should I know?</p>
  
  <p>Qt 5.4.</p>