I am faily new to wxWidgets and right now I am issuing a problem with a solution I am currently developing on.
basically the solution consists of 3 components:
1. the engine class (derived from wxApp)
2. a dialog class (wxDialog)
3. and a thread that does constant evaluations (inherits of wxThread of course )
Inside my thread there can occour two events that I'd like to give to my engine class for further processing (getting different information, showing up the dialog if needed and so on)...
I am now trying to get these events work for quite a while but until now with very little progress (most progress is on my understanding of wxwidgets but not enough to solve this on my own ). I've tried several ways: with event tables, as well as the connect functions (I personally favor those). Most times I ended up with invalid static_casts to unresolved function types when trying to do connect or creating the event table.
The following is an example how I try to do it
Code: Select all
// This is my "controller", that starts a thread and shows a dialog if its needed
class MyEngine : public wxApp
{
private:
MyWXDialog* pMyDlg;
MyThread* pMyThread;
public:
MyEngine()
{
// These Connects do not compile (wxEventHandler tries to cast statically to an "unresolved overloaded function type")
Connect(wxID_ANY, wxEVT_XXX, wxEventHandler(MyEngine::onThread1)), NULL, this);
Connect(wxID_ANY, wxEVT_XXX, wxEventHandler(MyEngine::onThread2)), NULL, this);
}
virtual ~MyEngine();
virtual bool OnInit()
{
pMyThread = new MyThread(this);
pMyDlg = new MyWXDialog( (wxWindow*)NULL );
return true;
}
void onThread1(wxEvent& evt)
{
// for example...
pMyDlg->Show();
SetTopWindow(pMyDlg);
}
void onThread2(wxEvent& evt)
{}
};
//This is the thread that does constant evaluations. It shall inform MyEngine if "event" one or two has been found
class MyThread : public wxThread
{
wxEvtHandler* pMain;
public:
MyThread(wxEvtHandler* ref)
{
pMain = ref;
}
protected:
virtual ExitCode Entry()
{
while(!TestDestroy() )
{
// When I find out that my first (second as well) event happened I need to tell that MyEngine to take further steps...
wxCommandEvent event(wxEVT_XXX);
pMain->AddPendingEvent(event);
}
}
};
Maybe you even have a better idea how to do this. I am open to (and thankfull for) every possible solution.
Best Regards and thanks in advance