hi there,
i'm in need of custom events because i have to handle complex data between
threads. I implemented everything like in the events tutorial and the docs
entry. it compiles fine but the event never gets to its destination.
here the event class:
============================================================================
class wxNetworkEvent : public wxNotifyEvent
{
private:
sTCP_Header m_sHeader;
public:
wxNetworkEvent( wxEventType commandType = wxEVT_NULL, int id
= 0 ) { ::wxNotifyEvent( commandType, id ); };
sTCP_Header getHeader() { return
m_sHeader; };
void setHeader( sTCP_Header
sHeader ) { m_sHeader = sHeader; };
};
============================================================================
The event declaration and event table:
============================================================================
EGIN_DECLARE_EVENT_TYPES()
DECLARE_EVENT_TYPE(wxEVT_NETWORK, -1)
END_DECLARE_EVENT_TYPES()
DEFINE_EVENT_TYPE(wxEVT_NETWORK)
typedef void (wxEvtHandler::*wxNetworkEventFunction)(wxNetworkEvent&);
#define EVT_NETWORK(id, fn) \
DECLARE_EVENT_TABLE_ENTRY( \
wxEVT_NETWORK, id, wxID_ANY, \
(wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent(
wxNetworkEventFunction, & fn ), \
(wxObject *) NULL \
),
BEGIN_EVENT_TABLE( Mainframe, wxFrame )
EVT_NETWORK( wxID_ANY, Mainframe::getIM )
END_EVENT_TABLE()
============================================================================
this is how the event is made in the worker thread (m_pkMainEvtHandler is a
member pointer to the main threads evt handler):
============================================================================
wxNetworkEvent evt(wxEVT_NETWORK, wxID_ANY);
evt.setHeader( sHeader );
evt.SetClientData( pvData );
m_pkMainEvtHandler->AddPendingEvent(evt);
============================================================================
and here the function where the event should get processed - but it never
jumps into:
============================================================================
void Mainframe::getIM( wxNetworkEvent& evt )
{
sTCP_Header tmp = evt.getHeader();
char *p = (char*)evt.GetClientData();
wxString strMsg = p;
unsigned int uiLen = 4;
strMsg = strMsg.Left( uiLen );
...
}
============================================================================
I hope you see whats wrong here - I dont get any error messages during
compile, link or execution time. also debugging didnt get me further. for
me it looks like it gets normally appended into the event handler queue.
kind regards, juergen
_______________________________________________
wx-users mailing list
[email protected]
http://lists.wxwidgets.org/mailman/listinfo/wx-users
On Sun, 13 Jul 2008 12:06:17 +0200 Jürgen Ladstätter <[email protected]> wrote:
JL> here the event class:
JL> ============================================================================
JL> class wxNetworkEvent : public wxNotifyEvent
It doesn't make sense to derive your custom event from wxNotifyEvent
because it can't be vetoed as inter-thread events are posted
asynchronously, not sent. Use wxCommandEvent as base class if you need
child-to-parent propagation or from wxEvent if you don't.
JL> {
JL> private:
JL> sTCP_Header m_sHeader;
JL>
JL> public:
JL> wxNetworkEvent( wxEventType commandType = wxEVT_NULL, int id
JL> = 0 ) { ::wxNotifyEvent( commandType, id ); };
JL>
JL> sTCP_Header getHeader() { return
JL> m_sHeader; };
JL> void setHeader( sTCP_Header
JL> sHeader ) { m_sHeader = sHeader; };
You didn't implement Clone() which must be done for events which are
posted (as they must be copied).
Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
_______________________________________________
wx-users mailing list
[email protected]
http://lists.wxwidgets.org/mailman/listinfo/wx-users
changed it now to:
class wxNetworkEvent : public wxCommandEvent
{
private:
sTCP_Header m_sHeader;
public:
wxNetworkEvent( wxEventType commandType = wxEVT_NULL, int id
= 0 ) { :: wxCommandEvent( commandType, id ); };
wxNetworkEvent( const wxNetworkEvent &event )
{this->m_eventType = event.m_eventType; this->m_sHeader = event.m_sHeader;};
virtual wxEvent *Clone() const { return new
wxNetworkEvent(*this); };
sTCP_Header getHeader() { return
m_sHeader; };
void setHeader( sTCP_Header
sHeader ) { m_sHeader = sHeader; };
};
still the event gets generated but does not get received by my function.
any more ideas?
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected] Im Auftrag von Vadim Zeitlin
Gesendet: Sonntag, 13. Juli 2008 17:13
An: [email protected]
Betreff: Re: custom events
On Sun, 13 Jul 2008 12:06:17 +0200 Jürgen Ladstätter
<[email protected]> wrote:
JL> here the event class:
JL>
============================================================================
JL> class wxNetworkEvent : public wxNotifyEvent
It doesn't make sense to derive your custom event from wxNotifyEvent
because it can't be vetoed as inter-thread events are posted
asynchronously, not sent. Use wxCommandEvent as base class if you need
child-to-parent propagation or from wxEvent if you don't.
JL> {
JL> private:
JL> sTCP_Header m_sHeader;
JL>
JL> public:
JL> wxNetworkEvent( wxEventType commandType = wxEVT_NULL, int id
JL> = 0 ) { ::wxNotifyEvent( commandType, id ); };
JL>
JL> sTCP_Header getHeader() { return
JL> m_sHeader; };
JL> void setHeader( sTCP_Header
JL> sHeader ) { m_sHeader = sHeader; };
You didn't implement Clone() which must be done for events which are
posted (as they must be copied).
Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
_______________________________________________
wx-users mailing list
[email protected]
http://lists.wxwidgets.org/mailman/listinfo/wx-users
_______________________________________________
wx-users mailing list
[email protected]
http://lists.wxwidgets.org/mailman/listinfo/wx-users