]> git.saurik.com Git - wxWidgets.git/commitdiff
mention wxThreadEvent in wxEVT_CATEGORY_THREAD and in wxEvtHandler::QueueEvent
authorFrancesco Montorsi <f18m_cpp217828@yahoo.it>
Thu, 19 Feb 2009 22:48:43 +0000 (22:48 +0000)
committerFrancesco Montorsi <f18m_cpp217828@yahoo.it>
Thu, 19 Feb 2009 22:48:43 +0000 (22:48 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59039 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

interface/wx/event.h

index de9ec40ad77ee8b9e3e13cb3bb625ece471499b1..65b08c16788c91b22e3c90ec24ff77917e651b1d 100644 (file)
@@ -54,6 +54,7 @@ enum wxEventCategory
         This category is for any event used to send notifications from the
         secondary threads to the main one or in general for notifications among
         different threads (which may or may not be user-generated).
+        See e.g. wxThreadEvent.
     */
     wxEVT_CATEGORY_THREAD = 16,
 
@@ -379,7 +380,7 @@ public:
         fields of this object are used by it, notably any wxString members of
         the event object must not be shallow copies of another wxString object
         as this would result in them still using the same string buffer behind
-        the scenes. For example
+        the scenes. For example:
         @code
             void FunctionInAWorkerThread(const wxString& str)
             {
@@ -392,6 +393,20 @@ public:
             }
         @endcode
 
+        Note that you can use wxThreadEvent instead of wxCommandEvent
+        to avoid this problem:
+        @code
+            void FunctionInAWorkerThread(const wxString& str)
+            {
+                wxThreadEvent evt;
+                evt->SetString(str);
+
+                // wxThreadEvent::Clone() makes sure that the internal wxString
+                // member is not shared by other wxString instances:
+                wxTheApp->QueueEvent( evt.Clone() );
+            }
+        @endcode
+
         Finally notice that this method automatically wakes up the event loop
         if it is currently idle by calling ::wxWakeUpIdle() so there is no need
         to do it manually when using it.