是否可以创建 gtkwidgets 的多维数组?具体来说是这样的:
mywidgetlist[2]["title"];
或者我应该以不同的方式来做这件事?我该怎么做?
基本上我有许多由较小的小部件组成的“小部件”(从 gtkbuilder 加载),我希望能够更改某些值,因此这个数组设置似乎更可取。
还有另一种方法可以做到这一点(除了使用信号等实际编码完整的小部件并将它们放入一个简单的数组中之外?)
Is it possible to create a multidimensional array of gtkwidgets? Specifically something like this:
mywidgetlist[2]["title"];
Or should I be doing this in a different way? How would I do this?
Basically I have a number of "widgets" (Loaded from gtkbuilder) composed of smaller widgets and I want to be able to change certain values, so this array setup seems preferable.
Is there another way of doing this (Other than actually coding a complete widget using signals etc and placing them in a simple array?)
发布评论
评论(1)
在 C 中,不能使用字符串来索引数组。或者,严格来说你可以,但这几乎不是你想要做的。
对于使用 glib 的 C 解决方案(如果您已经使用 GTK+,这很方便),请考虑
GHashTable
指针。In C, you cannot use a string to index into an array. Or, strictly speaking you can, but it's almost never what you want to do.
For C solution using glib (handy if you already use GTK+), consider a single-dimensional array of
GHashTable
pointers.