【发布时间】:2021-05-18 23:12:33
【问题描述】:
我有一个名为create_interface 的函数。在该函数中是打开菜单按钮的信号处理程序(菜单在create_interface 中创建)。我想传递窗口小部件并传递树视图小部件,因为当您打开文件时,树视图中的条目应该会显示出来。我尝试将它们作为结构传递,但是,虽然它可以工作,但 GTK 会生成一些错误消息。
// This is global.
struct everything
{
GtkWidget *window;
GtkWidget *tree_view;
}
GtkWidget *create_interface (void)
{
struct everything instance;
struct everything *widgets;
widgets = &instance;
...code here...
g_signal_connect(file_mi_open_file_dialog, "clicked", G_CALLBACK(open_file_dialog), widgets);
函数open_file_dialog 如下所示:
void open_file_dialog (GtkWidget *wid, gpointer data)
{
struct everything *sample_name = data;
...rest of code here...
我想知道是否有另一种组织程序的方法,这样您就不必拥有全局变量。
【问题讨论】:
-
"GTK 生成一些错误信息。"你会和我们分享这条信息吗?
标签: c global-variables gtk organization code-organization