我有一个 GUI 和一个工作线程,我想将数据从工作线程发送到 GUI。我正在使用 QueueEvent 和 wxThreadEvents 来保持模型视图分离。我以某种方式遇到了 baadf00d 错误。
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)&MyFrame::OutputData, this, EvtID);
...
}
MyFrame::OutputData(wxThreadEvent* event)
{
// should get data from MyThread,
// but outputs 0xBA, 0xAD, 0xF0, 0x0D in successive calls
output << event->GetInt();
}
MyThread::CreateOutputWithLocal()
{
wxThreadEvent event(wxEVT_THREAD, EvtID);
event.SetInt(getData());
//pFrame is a wxEvtHandler*
pFrame->QueueEvent(event.Clone());
}
MyThread::CreateOutputWithPointer()
{
wxThreadEvent* event = new wxThreadEvent(wxEVT_THREAD, EvtID);
event->SetInt(getData());
//pFrame is a wxEvtHandler*
pFrame->QueueEvent(event); // QueueEvent() takes control of the pointer and deletes it
}
使用wxThreadEvent
's SetPayload()
andGetPayload()
或 its SetExtraLong()
andGetExtraLong()
似乎没有任何区别。我需要什么才能让它工作?