title: How do I pass data from a thread using wxThreadEvent?
body: <p>I have a GUI and a worker thread, and I want to send data from the worker to the GUI. I'm using QueueEvent and wxThreadEvents to preserve model-view separation. I'm getting a baadf00d error somehow.</p>
  
  <pre><code>const int EvtID = 42;
  
  MyFrame::MyFrame()
  {
    ...
    // this seems to work correctly,
    //   but I'm including it in case it is part of the problem
    Bind(wxEVT_THREAD, (wxObjectEventFunction)&amp;MyFrame::OutputData, this, EvtID);
    ...
  }
  
  MyFrame::OutputData(wxThreadEvent* event)
  {
    // should get data from MyThread,
    //   but outputs 0xBA, 0xAD, 0xF0, 0x0D in successive calls
    output &lt;&lt; event-&gt;GetInt();
  }
  
  MyThread::CreateOutputWithLocal()
  {
    wxThreadEvent event(wxEVT_THREAD, EvtID);
    event.SetInt(getData());
    //pFrame is a wxEvtHandler*
    pFrame-&gt;QueueEvent(event.Clone());
  }
  
  MyThread::CreateOutputWithPointer()
  {
    wxThreadEvent* event = new wxThreadEvent(wxEVT_THREAD, EvtID);
    event-&gt;SetInt(getData());
    //pFrame is a wxEvtHandler*
    pFrame-&gt;QueueEvent(event); // QueueEvent() takes control of the pointer and deletes it
  }
  </code></pre>
  
  <p>Using <code>wxThreadEvent</code>'s <code>SetPayload()</code> and <code>GetPayload()</code> or its <code>SetExtraLong()</code> and <code>GetExtraLong()</code> doesn't seem to make any difference. What do I need to get this to work?</p>