我正在使用wxWidgets 3.1.3和Boost 1.73。
正在处理模块化应用程序的自定义首选项对话框,这是标题的相关部分:
class PreferencesWindow : public wxDialog {
public:
PreferencesWindow(...); // Constructor
protected:
wxButton* DialogButtonsApply;
wxButton* DialogButtonsCancel;
wxButton* DialogButtonsOK;
wxTreebook* TreeBook;
private:
enum {
// Enumerated Window Ids
};
// Event Handlers
virtual void OnTreeSelection(wxTreeEvent& event);
virtual void OnApplyButton(wxCommandEvent& event);
virtual void OnCancelButton(wxCommandEvent& event);
virtual void OnOkayButton(wxCommandEvent& event);
DECLARE_EVENT_TABLE();
pt::ptree newPrefs;
public:
const pt::ptree &getNewPrefs() const;
void setNewPrefs(const pt::ptree &newPrefs);
};
pt::ptree
对象是boost::property_tree
s的typedef。在整个应用程序中都可以访问ptree
中的全局MyApp
。在构建期间,对话框会动态加载每个模块的首选项页面。每个页面都是派生的wxPanel
。 newPrefs
包含修改的首选项。我需要面板能够访问和更新newPrefs
,以便当用户退出对话框时,该对话框可以负责更新主要的首选项数据-从而更新磁盘上的首选项文件/注册表。
我该怎么做?
我不确定问题出在哪里,也就是什么问题对您不起作用,但是您可能会发现TransferDataFromWindow()很有用:当接受对话框时会调用此方法,通常您会覆盖它以复制数据从用户界面进入内部数据结构。
请注意,您应该not为标准wxID_OK
和wxID_APPLY
按钮定义任何处理程序,因为默认行为应该很好(此外,如果您确实定义了这些处理程序,则不会将它们设为虚拟没有太大意义。