2016-07-23 11 views
0

Ich habe jetzt eine kleine Anwendung mit gtkmm entwickelt. Meine Anwendung besteht aus zwei Klassen, einer Klasse für mein Fenster (Hauptfenster) und einer anderen Klasse, die laufende Prozesse auf meinem Rechner aufruft. Hauptfenster Meine Klasse enthält ein Listen-Widget.Access MainWindow Widget aus einer anderen Klasse gtkmm

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 
} 

Ich wünschte, ich könnte diese Liste von meiner anderen Klasse mit Thic-Code füllen. Aber wenn ich versuche my_list zuzugreifen ich einen Fehler: error: m_list was not declared in this scope

row (Gtk::TreeModel::Row) wird als Argument für meine Funktion übergeben

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); 

Wie kann ich ein Widget Hauptfenster meiner Klasse von einer anderen Klasse?

Antwort

0

Allgemeine Lösung:

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 
     } 
} 

Verbrauch:

A a; 
B b; 

a.fillByOtherClass(b);