title: Managing QUdpSocket in multithreaded environment
body: <p>I have problem with deleting QUdpSocket in my program. Problem is: I create UdpSocket in one thread, and then delete it in another. To simplify my code I have this:</p>
  
  <pre><code>class SocketHandler : public QObject
  {
      Q_OBJECT
  public:
      SocketHandler():
          socket(this)
      {
          socket.bind(8888);
      }
      ~SocketHandler();
  
  private:
      QUdpSocket socket;
  };
  
  class ThreadStorage
  {
  public:
      ThreadStorage():
           handler(new SocketHandler()),
           thread(new QThread())
      {
           handler-&gt;moveToThread(thread);
      }
      ~ThreadStorage();
  
  private:
  
      SocketHandler* handler;
      QThread* thread;
  };
  
  class Killer : public QObject
  {
      Q_OBJECT
  public:
   Killer(ThreadStorage* stor):
       storage(stor)
   {
   }
  
  private:
      ThreadStorage* storage;
  public slots:
      void kill()
      {
          delete storage;
      }
  </code></pre>
  
  <p>};</p>
  
  <p>And then I have slot connected to button in <code>MainWindow</code>:</p>
  
  <pre><code>void MainWindow::onButton()
  {
       ThreadStorage* storage = new ThreadStorage();
  
       QTimer* timer = new QTimer();
       timer-&gt;setInterval(2000);
       timer-&gt;setSingleShot(true);
  
       Killer* killer = new Killer( storage);
       connect(timer, SIGNAL(timeout()), killer, SLOT(kill()));
  
  
       QThread* thread = new QThread();
       connect(thread, SIGNAL(started()), timer, SLOT(start()));
  
       timer-&gt;moveToThread(thread);
       killer-&gt;moveToThread(thread);
       thread-&gt;start();
  }
  </code></pre>
  
  <p>When socket is deleted I have error:<br>
  <strong>ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects owned by a different thread. Current thread 7287a0. Receiver '' (of type 'QNativeSocketEngine') was created in thread 709838", file kernel\qcoreapplication.cpp, line 521</strong></p>
  
  <p>I'm using QT with msvc2013+opengl.<br>
  I understand memory leaks and other stupid errors in this particular code. This code is only for you to see what happens in my big program. It is just Minimal, Complete, and Verifiable example.<br>
  So, how do I properly manage UdpSocket in multithreaded app? Thanks.</p>