我正在尝试将gtk.treeview导出到文本格式中。这就像在应用程序上使用ListStore模型在树景中呈现数据的应用程序上的文本函数的导出。
有人可以帮助您提供有关如何有效解析gtk.treeview并以简单的文本格式表示的示例代码。
作为起点,请考虑来自valadoc的此代码:
public static int main (string[] args) {
// Create a ListStore:
Gtk.ListStore list_store = new Gtk.ListStore (2, typeof (string), typeof (int));
Gtk.TreeIter iter;
// Insert data: (0: State, 1: Cities)
list_store.append (out iter);
list_store.set (iter, 0, "Burgenland", 1, 13);
list_store.append (out iter);
list_store.set (iter, 0, "Carinthia", 1, 17);
list_store.append (out iter);
list_store.set (iter, 0, "Lower Austria", 1, 75);
list_store.append (out iter);
list_store.set (iter, 0, "Upper Austria", 1, 32);
list_store.append (out iter);
list_store.set (iter, 0, "Salzburg", 1, 10);
list_store.append (out iter);
list_store.set (iter, 0, "Styria", 1, 34);
list_store.append (out iter);
list_store.set (iter, 0, "Tyrol", 1, 11);
list_store.append (out iter);
list_store.set (iter, 0, "Vorarlberg", 1, 5);
list_store.append (out iter);
list_store.set (iter, 0, "Vienna", 1, 1);
// Output:
// ``Entry: Burgenland 13``
// ``Entry: Carinthia 17``
// ``Entry: Lower Austria 75``
// ``Entry: Upper Austria 32``
// ``Entry: Salzburg 10``
// ``Entry: Styria 34``
// ``Entry: Tyrol 11``
// ``Entry: Vorarlberg 5``
// ``Entry: Vienna 1``
for (bool next = list_store.get_iter_first (out iter); next; next = list_store.iter_next (ref iter)) {
Value val1, val2;
list_store.get_value (iter, 0, out val1);
list_store.get_value (iter, 1, out val2);
stdout.printf ("Entry: %st%dn", (string) val1, (int) val2);
}
return 0;
}
您还应该阅读GTK.Treemodel接口的顶级文档。