I am currently testing a freshly built wxwidgets 2.9.1 and I do not understand the documentation concerning the events must be posted.
Until now, when I have a worker thread that post events to the main gui, for example a image loader thread that send the loaded image filename, I used:
Code: Select all
void ImageLoaderThread::OnImageLoaded(const wxString& imageFileName)
{
ImageLoaderEvent evt(wxEVT_IMAGELOADER_IMAGEREADY,imageFileName);
evt.SetId(_destWindow->GetId());
_destWindow->AddPendingEvent(evt);
}
ImageLoaderEvent is a wxNotifyEvent-inherited class.
From what I read in the doc, am I supposed to use this code ?
Code: Select all
evt.SetId(_destWindow->GetId());
_destWindow->ProcessWindowEvent(evt);
Also I read in the doc stuff like wxPostEvent (which is not thread safe), wxQueueEvent (which is thread safe), wxThreadEvent (which is inter-thread safe ?), QueueEvent, and the fact that wxString::c_str() should be used to make a deep copy of a string to send in the event, but Clone() would be also important for this ?
Well, after some thoughts, I guess I can write my code like this:
Code: Select all
void ImageLoaderThread::OnImageLoaded(const wxString& imageFileName)
{
ImageLoaderEvent evt(wxEVT_IMAGELOADER_IMAGEREADY,imageFileName);
evt.SetId(_destWindow->GetId());
wxQueueEvent(_destWindows, evt.Clone());
}
Or do I need to pass imageFileName.c_str() instead of imageFileName in the ctor of ImageLoaderEvent ?
Any thoughts ?
Thanks.