Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / Unable to disconnect dynamic events

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Unable to disconnect dynamic events
#3459
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,
		wxEVT_COMMAND_MENU_SELECTED,
		(wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction)&wx_Frame::OnSettingsLanguage,
		(wxObject*)mpo_ObjUserData);
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... ;-)

Sabine

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

upCASE
-----------------------------------
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
#3474
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:
this->Disconnect(lo_MenuID);

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.

Sabine
Message4. Re: Unable to disconnect dynamic events
#3478
Posted by: upCASE 2004-03-08 19:23:16
Hi!
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)
    union
    {
        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.

upCASE
-----------------------------------
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
#3483
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 ;-)

Sabine
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
¥860.00 ·
 
 
¥410.00 ·
 
 
¥288.00 ·
 
 
¥918.00 ·
 
 
¥288.00 ·
 
 
¥264.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0