我现在用gtkmm开发了一个小应用程序。我的应用程序包含两个类,一个用于我的窗口的类(mainwindow)和另一个用于检索我的机器上正在运行的进程的类。 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
}
我希望我可以用我的其他课程填写此代码。但是当我尝试访问my_list时出现错误:
error: m_list was not declared in this scope
row
(Gtk::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);
如何从另一个类访问我的类的窗口小部件主窗口?
答案 0 :(得分:0)
通用解决方案:
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
}
}
用法:
A a;
B b;
a.fillByOtherClass(b);