Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 派生wxPanel';s控制访问it中的数据';它包含wxDialog吗?_C++_Boost_Wxwidgets - Fatal编程技术网

C++ 派生wxPanel';s控制访问it中的数据';它包含wxDialog吗?

C++ 派生wxPanel';s控制访问it中的数据';它包含wxDialog吗?,c++,boost,wxwidgets,C++,Boost,Wxwidgets,我正在使用wxWidgets 3.1.3和Boost 1.73 使用模块化应用程序的自定义首选项对话框时,标题的相关部分如下: class PreferencesWindow : public wxDialog { public: PreferencesWindow(...); // Constructor protected: wxButton* DialogButtonsApply; wxButton* DialogButtonsCancel; wxBut

我正在使用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_树的typedef。在
MyApp
中有一个全局
ptree
,可在整个应用程序中访问。在构建过程中,对话框会动态加载每个模块的首选项页面。每个页面都是一个派生的
wxPanel
newPrefs
包含修改后的首选项。我需要面板能够访问和更新
newPrefs
,这样当用户退出对话框时,对话框可以负责更新主首选项数据,从而更新磁盘上的首选项文件/注册表

我该怎么做


更新#1 澄清:

在构建
首选项swindow
的过程中,将创建每个控件并将其放置在其大小设定器中<代码>面板
,派生自
wxPanel
,然后创建并添加到
TreeBook->AddPage(面板名称,“面板标题”)中的对话框中

通常,该对话框将从主应用程序窗口作为ShowModal调用。然而,现在,当我为PreferencesWindow创建基础时,主窗口现在被绕过。
MyApp::OnInit()
直接创建并显示对话框


我将使“首选项”对话框负责将选项写入磁盘,而不仅仅是主首选项变量。

我不确定到底是什么问题,即什么不适合您,但您可能会发现它很有用:当对话框被接受时,就会调用此方法,您通常会覆盖它以将数据从UI复制到内部数据结构中


请注意,您不应该为标准的
wxID\u OK
wxID\u APPLY
按钮定义任何处理程序,因为默认行为应该很好(另外,如果您确实定义了这些处理程序,那么将它们虚拟化就没有多大意义了)。

您可以显示一些更实际的代码吗?如何实例化该对话框以及构造函数中的内容?如果您询问如何实现它,那么基本思想是:您有一个全局wxApp指针。在对话框构造函数中,从全局指针pt::ptree data加载数据。然后调用
dlg.showmodel()
,它返回
wxID\u OK
以接受数据,或返回
wxID\u CANCEL
以拒绝数据。因此,当您获得
wxID_OK
时,您将调用公共访问器函数,该函数将重新返回pt::ptree的对象,并将其分配给wxApp中的对象。