Guidance Forums / wxWidgets (wxWindows) in C++ / Unable to disconnect dynamic events

Search 搜索
Home Home

Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Unable to disconnect dynamic events
Posted by: 2004-03-05 21:10:10
Hallo all,

I dynamically attach some menu items to one function using Connect():
mpo_ObjUserData = new wx_EvtData(str_Language);
this->Connect(	lo_MenuID,
This works fine, in the function the UserData object is read and processed.

But when closing the programm it fails in disconnecting the dynamic event table entries in line 1010 in event.cpp:
if (entry->m_callbackUserData)
                delete entry->m_callbackUserData;
I tried to delete the UserData object before disconnecting but this didn't change anything.
I'm confused. What can I do? Can I do something?

Any Ideas? Please... ;-)


Message2. Re: Unable to disconnect dynamic events
Posted by: upCASE 2004-03-06 00:16:53
Just a simple quick thought: Have you tried Disconnect() before you close the app?

If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message3. Re: Unable to disconnect dynamic events
Posted by: 2004-03-08 15:40:20
Hi upCase,

you again *smile*

The second code snippet from my question is from INSIDE Disconnect() in (wx-)event.cpp!

I do:

in my OnQuit event handler. I can follow the programm to that point where it tries to delete the userdata, there it crashes. The debugger stops at a complete different point in my app where the code is creating GUI-elements?!? I don't understand it...

Userdata are made this way:
(wxObject*)(void*)new wx_EvtData(str_Textstring)

wx_EvtData is a class with only one public string member variable.

When connecting the events without userdata, disconnecting is no problem.

Message4. Re: Unable to disconnect dynamic events
Posted by: upCASE 2004-03-08 19:23:16
Just strippped this from the event.h source:

 // The user data: either an object which will be deleted by the container
    // when it's deleted or some raw pointer which we do nothing with - only
    // one type of data can be used with the given window (i.e. you cannot set
    // the void data and then associate the container with wxClientData or vice
    // versa)
        wxClientData *m_clientObject;
        void         *m_clientData;

    // what kind of data do we have?
    wxClientDataType m_clientDataType;

    // client data accessors
    virtual void DoSetClientObject( wxClientData *data );
    virtual wxClientData *DoGetClientObject() const;

    virtual void DoSetClientData( void *data );
    virtual void *DoGetClientData() const;

So, if I get this correctly, maybe try to set the object data later on using DoSetClientObject(). Try the method that takes a void* unless you really derived your object from wxClientData or wxObject.

If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message5. Re: Unable to disconnect dynamic events
Posted by: 2004-03-09 16:35:02
Hi again :-)

well, this was a good advice. A just made my wx_ClientData class be a real child of wxObject and it worked :-) The simple parsing to *wxObject that I did before was not enough.
The only thing I'm now a little bit afraid of is that closing the programm needs quite a lot of time? Hopefully this is not a new terrible bug inside...

So have a nice day till my next problem ;-)

Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
© Thu 2024-6-20  Guidance Laboratory Inc. Hits:0