gpt4 book ai didi

c - GTK+ 2.0 C 奇怪的结构和 g_signal_connect_swapped

转载 作者:太空宇宙 更新时间:2023-11-04 04:39:21 25 4
gpt4 key购买 nike

我有以下声明:

typedef struct window_and_search_entry
{
GtkWidget *window;
GtkWidget *search_entry;
} WINDOW_AND_SEARCH_ENTRY;

and then in main:

GtkWidget *window;
GtkWidget *search_entry;

...

WINDOW_AND_SEARCH_ENTRY window_and_search_entry;
window_and_search_entry.window = window;
window_and_search_entry.search_entry = search_entry;

还有那两个:

g_signal_connect_swapped(G_OBJECT(search_entry), "activate", G_CALLBACK(analyse), (gpointer) &window_and_search_entry);

g_signal_connect_swapped(G_OBJECT(do_it_button), "clicked", G_CALLBACK(analyse), (gpointer) &window_and_search_entry);

我想创建接受文本和窗口的函数,对其进行一些操作,如果发生错误,则使用其他接受窗口作为参数的函数将其打印出来

ELEMENT *analyse(GtkWidget *widget, gpointer user_data)
{
//((WINDOW_AND_SEARCH_ENTRY *) user_data)->search_entry;
GtkWidget *a = ((WINDOW_AND_SEARCH_ENTRY*)(user_data))->search_entry;
const char *text = gtk_entry_get_text(GTK_ENTRY(a));
g_print("%s\n", text);




ELEMENT *heap[100];
int index = 0;


return heap[1];
}

我尝试了很多变体,但在 entry_box 中输入内容后按回车或按钮后出现“段错误”。我想将文本打印到控制台。请帮助我,谢谢。

最佳答案

您的analyse 回调需要g_signal_connect,而不是g_signal_connect_swapped。也不需要转换指针:G_CALLBACK() 宏已经转换了整个函数,所以这就足够了:

ELEMENT *analyse(GtkWidget *widget, WINDOW_AND_SEARCH_ENTRY *data)

使用 g_signal_connect_swapped 它将是:

ELEMENT *analyse(WINDOW_AND_SEARCH_ENTRY *data, GtkWidget *widget);

这个交换版本只是对已有函数的 C 便利,例如你可以这样做:

g_signal_connect_swapped(G_OBJECT(search_entry), "activate",
G_CALLBACK(g_print), "Activate signal called");

关于c - GTK+ 2.0 C 奇怪的结构和 g_signal_connect_swapped,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28000383/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com