带有自定义事件的wxWidgets事件表

时间:2014-07-09 11:28:49

标签: events wxwidgets

我尝试在wxWidgets应用程序中实现自定义事件,但我无法以正确的方式编写事件表宏。

我用来实现事件的文件如下:


.h文件

#ifndef __APP_FRAME_H__
#define __APP_FRAME_H__


#include "wx/wxprec.h"

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include <wx/evtloop.h>
#include "wxApp.h"
#include "sampleCefApp.h"


class appFrame: public wxFrame
{
public:
    appFrame(const wxString &title, const wxPoint &pos, const wxSize &size);
private:
    int OnExit();
    void OnCefStartEvent(wxCommandEvent &e);
    DECLARE_EVENT_TABLE()
};

#endif

.cpp文件

// File : appFrame.cpp

#include "appFrame.h"


wxDEFINE_EVENT(CEF_START_EVT, wxCommandEvent)

void appFrame::OnCefStartEvent(wxCommandEvent &e)
{    
    CefRunMessageLoop();
}

int appFrame::OnExit(){
    CefShutdown();
    Destroy();
    return 0;
}

appFrame::appFrame(const wxString &title, const wxPoint &pos, const wxSize &size)
    : wxFrame(NULL, wxID_ANY, title, pos, size)
{

}

wxBEGIN_EVENT_TABLE(appFrame, wxFrame)
    EVT_COMMAND(wxID_ANY, CEF_START_EVT, appFrame::OnCefStartEvent)
wxEND_EVENT_TABLE()

当我构建make文件时,我收到以下错误:

../src/appFrame.cpp:4:15: error: expected constructor, destructor, or type conversion before ‘(’ token
../src/appFrame.cpp:24:2: error: expected constructor, destructor, or type conversion before ‘wxEventTableEntry

我认为问题与错误放置事件表宏有关。

我想知道究竟是什么问题以及如何解决它?

1 个答案:

答案 0 :(得分:0)

wxDEFINE_EVENT()宏之后需要一个分号(对于几乎所有带有wx前缀的宏,它们始终需要分号,与没有前缀的旧宏不同。)

像往常一样,请参阅sample以获取使用此宏的示例。

相关问题