wxNotifyEvent does not work Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
kea_
Experienced Solver
Experienced Solver
Posts: 59
Joined: Wed Oct 17, 2007 7:32 am

wxNotifyEvent does not work

Post by kea_ » Mon Jul 21, 2008 12:03 pm

Hello together,

I try to program my own class with an event in it.
But unfortunately I get the error: invalid static_cast from type 'void(fmFrame::*)(wxCommandEvent&)' to type 'void(wxEvtHandler::*)(csDatabase&)'

I do not know what's wrong. Can any body give me a helping hand?

I'm using the wxDev-C++

her is the source:

csDatabase.h

Code: Select all

#ifndef csDatabase_h
#define csDatabase_h

#include "csConfig.h"
#include <wx/event.h>


// For compilers that support precompilation, includes "wx.h".
#include <wx/wxprec.h>

#ifdef __BORLANDC__
#pragma hdrstop
#endif


class csDatabase : public wxNotifyEvent
{
	public:
        // F U N C T I O N S
        csDatabase(wxEventType commandType = wxEVT_NULL, int id = 0);
        csDatabase(const csDatabase &event);
        wxEvent *Clone();
        void CallEvent();

        DECLARE_DYNAMIC_CLASS(csDatabase);

    private:
        // P A R A M E T E R S
        // F U N C T I O N S
        // E V E N T S

        // E N U M
};

BEGIN_DECLARE_EVENT_TYPES()
    DECLARE_EVENT_TYPE(myEVT_SAVING, -1)
END_DECLARE_EVENT_TYPES()

typedef void (wxEvtHandler::*csDatabaseFunction)(csDatabase&);


#define EVT_SAVING(id, fn) \
    DECLARE_EVENT_TABLE_ENTRY( \
        myEVT_SAVING, id, wxID_ANY, \
        (wxObjectEventFunction)(wxEventFunction) wxStaticCastEvent(csDatabaseFunction, &fn ), (wxObject *) NULL ),

#endif
csDatabase.cpp

Code: Select all

#include "csDatabase.h"

//IMPLEMENT_DYNAMIC_CLASS(csDatabase, wxEvent)
DEFINE_EVENT_TYPE(myEVT_SAVING)



csDatabase::csDatabase(wxEventType commandType, int id)
           :wxNotifyEvent(commandType, id){
}


csDatabase::csDatabase(const csDatabase &event)
           :wxNotifyEvent(event){
}


wxEvent *csDatabase::Clone(){
    return new csDatabase(*this);
}


void csDatabase::CallEvent(){
    for(int i = 0; i < 10; i++){
        if(i = 5){
            csDatabase event(myEVT_SAVING, GetId());
            event.SetEventObject(this);
            event.ProcessEvent(event);
            GetEventHandler()->ProcessEvent(event);
        }
    }
}
Frame.cpp

Code: Select all

BEGIN_EVENT_TABLE(fmFrame, wxFrame)
    EVT_BUTTON(ID_BUTTON1, fmFrame::OnButton)
    EVT_BUTTON(ID_BUTTON2, fmFrame::OnButton)
    EVT_SAVING(-1, fmFrame::OnSaving)
END_EVENT_TABLE()

void fmFrame::OnSaving(wxCommandEvent &event){
  // do something
}
thanks for any help...
kea_

Rabah
Earned some good credits
Earned some good credits
Posts: 133
Joined: Fri Jun 08, 2007 8:21 am

Post by Rabah » Mon Jul 21, 2008 12:47 pm

I get it with wxEvent.
why do not try to inherit from wxEvent?

Rabah

kea_
Experienced Solver
Experienced Solver
Posts: 59
Joined: Wed Oct 17, 2007 7:32 am

Post by kea_ » Mon Jul 21, 2008 1:14 pm

Hello,

thanks for the answer...

Do you have an example that works?
Can you show it to me?

Thanks
kea_

Rabah
Earned some good credits
Earned some good credits
Posts: 133
Joined: Fri Jun 08, 2007 8:21 am

Post by Rabah » Mon Jul 21, 2008 1:24 pm

ok!

in the .h:

Code: Select all

class LEAEvent : public wxEvent
{
	public:
		LEAEvent();
		LEAEvent(const LEAEvent& evt);
		~LEAEvent();
		wxEvent* Clone() const;
		
       private :
                void* m_data;
                //PARAMETER
};
in the .cpp

Code: Select all

BEGIN_DECLARE_EVENT_TYPES()
	DECLARE_EVENT_TYPE(wxEVT_LEA, -1)
END_DECLARE_EVENT_TYPES()

DEFINE_EVENT_TYPE(wxEVT_LEA)

typedef void (wxEvtHandler::*LEAEventFunction)(LEAEvent&);

#define EVT_LEA(fn) \
    DECLARE_EVENT_TABLE_ENTRY(wxEVT_LEA, -1, -1, \
    (wxObjectEventFunction) (wxEventFunction) \
    wxStaticCastEvent( LEAEventFunction, & fn ), (wxObject *) NULL ),

LEAEvent::LEAEvent():wxEvent(),m_typeEvent(0)
{
	SetEventType(wxEVT_LEA);
}


LEAEvent::LEAEvent(const LEAEvent& evt):
 						wxEvent(evt),
 						m_data(evt.m_data),...
{

}

LEAEvent::~LEAEvent()
{
}


wxEvent* LEAEvent::Clone() const
{
	return new LEAEvent(*this);
}



in a the class it use my EVT_LEA :

Code: Select all

BEGIN_EVENT_TABLE(LEAApp, wxApp)
	EVT_LEA(LEAApp::OnLEAEvent)
END_EVENT_TABLE()

LEAApp::OnLEAEvent(LEAEvent& evt)
{
//do somethink;
}
There are lots of difference, the main one :
we do not call the event in the same way.
you look to use a Id -1 I use directly the event handler as you can see in the code of the class it use My event EVT_LEA

Rabah

kea_
Experienced Solver
Experienced Solver
Posts: 59
Joined: Wed Oct 17, 2007 7:32 am

Post by kea_ » Tue Jul 22, 2008 6:22 am

Hello Rabah,

thank you for your example. I had a lot of problems (
I had to use: wxStaticCastEvent(wxCommandEventFunction, & fn), (wxObject *) NULL ),
instead of:
wxStaticCastEvent(csDatabaseFunction, & fn), (wxObject *) NULL ),
) to compile your example but now it works. Excepting for the fire of the event. How do I fire the event now. With the wxEvtHandler?

What developmenttool do you use? Maybe a better one than the wxDev?

Many thanks for your help!
Greetings kea_

framepointer
Super wx Problem Solver
Super wx Problem Solver
Posts: 264
Joined: Mon Aug 07, 2006 3:25 pm
Location: Baia Mare, Romania
Contact:

Post by framepointer » Tue Jul 22, 2008 7:31 am

You might wanna take a look at this thread:
http://forums.wxwidgets.org/viewtopic.p ... highlight=

It has the solution for inhereting wxNotifyevent.


Regards
Software is like sex,
It's better when it's free.
~Linus Torvalds

kea_
Experienced Solver
Experienced Solver
Posts: 59
Joined: Wed Oct 17, 2007 7:32 am

Post by kea_ » Tue Jul 22, 2008 8:08 am

Yes I've seen this stuff...
Thank you for the link.

But it didn't help me before.
I've got error over error....
So I needed help with an example who is working.
But maybe I'm to stupid.

Greetings Kea_

framepointer
Super wx Problem Solver
Super wx Problem Solver
Posts: 264
Joined: Mon Aug 07, 2006 3:25 pm
Location: Baia Mare, Romania
Contact:

Post by framepointer » Tue Jul 22, 2008 8:15 am

The example works :) I use similar code for every custom event I create.

Regards
Software is like sex,
It's better when it's free.
~Linus Torvalds

Rabah
Earned some good credits
Earned some good credits
Posts: 133
Joined: Fri Jun 08, 2007 8:21 am

Post by Rabah » Tue Jul 22, 2008 12:44 pm

Hello _kea

I code on linux I do not have a developmebnt tool I have just written a Makefile and used and editor to write my code.

I do not have tried with wxDev.

And else to fire the Event I write :

Code: Select all

LEAEvent evt;
///put parameter
evt.m_data = ...  ;
ptr->AddPendingEvent(evt);
ptr must be a pointer of class which inherits from wxEvtHandler for less

Rabah

kea_
Experienced Solver
Experienced Solver
Posts: 59
Joined: Wed Oct 17, 2007 7:32 am

Post by kea_ » Thu Jul 24, 2008 1:22 pm

Yeahhh....., juhuiiiii......,

it works, great....

Thank you for your great help!!!

kea_

Post Reply