wxWidgets编程注意事项

来源:互联网 发布:linux 查看mysql进程 编辑:程序博客网 时间:2024/06/07 00:37

1. 在类中定义对象:

{

    wxAuiManager m_mgr;

}

 

编译无法通过,输出类似错误:

demo_demo.o: In function `MyFrame::~MyFrame()':
demo.cpp:(.text+0x6491): undefined reference to `wxAuiManager::UnInit()'
demo.cpp:(.text+0x64a7): undefined reference to `wxAuiManager::~wxAuiManager()'
demo.cpp:(.text+0x64cb): undefined reference to `wxAuiManager::~wxAuiManager()'

原因在于makefile中没有包含库文件(aui),修改为:

g++ -o demo demo_demo.o   `wx-config --libs aui,core,base`

搞定!

 

 2. 确定类

window->IsKindOf(CLASSINFO(wxAuiNotebook))

这个类会用先调用:

DECLARE_DYNAMIC_CLASS

IMPLEMENT_DYNAMIC_CLASS

说明自己是什么类

 

 

3. 控件布局:

将界面中控件放入wxBoxSizer,所有控件在wxPanel *m_panel中:

wxBoxSizer sizer = new wxBoxSizer(wxVERTICAL);

.....

    m_panel->SetAutoLayout( true );
    m_panel->SetSizer( mainsizer );

sizer->SetSizeHints( this);

 

如果是wxSashLayoutWindow:

MyFrame::OnSize()

{

    wxLayoutAlgorithm layout;
    layout.LayoutFrame(this);

}

 

当button等空间size变化的时候,如果调用wxFlexGridSizer,变化时:

SetSizeHints()

FitInside()

在sample/scroll中。

 

OnSize对于控件有影响,比如:

MyFrame::OnSize()

MyPanel::OnSize()

 

类似于vtable的错误:

wellGrid_wellGrid.o: In function `WellGrid::WellGrid(wxWindow*, int, wxPoint const&, wxSize const&, long, wxString const&)':
wellGrid.cpp:(.text+0x3f2): undefined reference to `vtable for WellGrid'
wellGrid.cpp:(.text+0x3ff): undefined reference to `vtable for WellGrid'
wellGrid_wellGrid.o: In function `WellGrid::WellGrid(wxWindow*, int, wxPoint const&, wxSize const&, long, wxString const&)':
wellGrid.cpp:(.text+0x560): undefined reference to `vtable for WellGrid'
wellGrid.cpp:(.text+0x56d): undefined reference to `vtable for WellGrid'
wellGrid_wellGrid.o: In function `WellGrid::WellGrid()':
wellGrid.cpp:(.text+0x69c): undefined reference to `vtable for WellGrid'
有可能:

1.在*.h头文件中,声明了DECLARE_EVENT_TABLE(),在cpp中没有BEGIN_EVENT_TABLE()。。。

2.如果在*.h中,声明了虚函数,virtual void DrawRowLabels()。。。,没有在cpp中实现,也会出现此类错误。

 

 

wxString

1.

char* name = "TestName";

wxString::Format(_T("%s"), name);

执行的时候,会弹出warning,改为:

wxString::FromAscii(name);

it's OK.

 

原创粉丝点击