简体   繁体   English

从另一个类gtkmm访问MainWindow小部件

[英]Access MainWindow widget from another class gtkmm

I now developed a small application with gtkmm. 我现在使用gtkmm开发了一个小型应用程序。 My application consists of two classes, a class for my window (mainwindow) and another class that will retrieve running processes on my machine. 我的应用程序包含两个类,一个是我的窗口(主窗口)类,另一个是将检索计算机上正在运行的进程的类。 mainwindow my class contains a List widget. mainwindow我的班级包含一个List小部件。

class MainWindow : public Gtk::Window
{
    public:
    MainWindow();
    virtual ~MainWindow();

    bool displayStatus(GdkEventCrossing* event, std::string message);
    bool hideStatus(GdkEventCrossing* event);

    List m_list;
    ...other widget
}

I wish I could fill this list from my other class with thic code. 我希望我可以在其他班级中用thic代码填充此列表。 But when I try to access my_list I get an error : error: m_list was not declared in this scope 但是,当我尝试访问my_list时,出现错误: error: m_list was not declared in this scope

row ( Gtk::TreeModel::Row ) is passed as an argument to my function rowGtk::TreeModel::Row )作为参数传递给我的函数

PROCTAB* proc = openproc(PROC_FILLARG | PROC_FILLSTAT);

 while (proc_t* proc_info = readproc(proc, NULL)) {

    row[m_list.m_col_tid] = proc_info->tid;
    row[m_list.m_col_ppid] = proc_info->ppid;
    row[m_list.m_col_cmdline] = proc_info->cmd;
    row[m_list.m_col_utime] = proc_info->utime;
    row[m_list.m_col_stime] = proc_info->stime;

    freeproc(proc_info);
 }

 closeproc(proc);

How can I access a widget mainwindow my class from another class? 如何从另一个班级访问我的班级的窗口小部件主窗口?

Generic solution: 通用解决方案:

class B;
class A
{
    public:
        void fillByOtherClass(const B& b)
        {
             b.fill(list_to_fill);
        }
    private:
        List list_to_fill;

}

class B
{
    public:
        void fill(List& list) const
        {
            //fill it
        }
}

Usage: 用法:

A a;
B b;

a.fillByOtherClass(b);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM