因此,我是gtk的新手,我正在尝试制作一个登录表单,并且我需要在按下“提交”按钮时同时发送用户名和密码。我怎样才能做到这一点? 我的代码:
const void button_clicked (GtkWidget *widget,gpointer data)
{
const gchar* text;
text = gtk_entry_get_text(GTK_ENTRY(data));
write(lala,text,100);
}
GtkWidget*window,*label_username,*label_password,*layout,*entry_username,*entry_password,*submit_button;
entry_username = gtk_entry_new();
entry_password = gtk_entry_new();
submit_button = gtk_button_new_with_label("Sumbit");
g_signal_connect(submit_button,"clicked",G_CALLBACK(button_clicked),entry_username;
如何使Submit_button函数从entry_username和entry_password接收文本?谢谢!
答案 0 :(得分:1)
在gtk中,对于此类情况,最好将包含小部件作为成员的结构传递给回调函数...
typedef struct MainWindow
{
GtkWidget *entry_username, *entry_password;
}MAINWINDOW;
int main(
MAINWINDOW *mainwindow = malloc(sizeof(MAINWINDOW));
mainwindow->entry_username = gtk_entry_new();
mainwindow->entry_password = gtk_entry_new();
g_signal_connect(submit_button,"clicked",G_CALLBACK(button_clicked),mainwindow);
}
const void button_clicked (GtkWidget *widget,gpointer data)
{
MAINWINDOW *mainwindow = data;
//now you have both the widget's
// modify em as per your wish :)
}
这是一个非常粗糙的例子。但是类似这样的方法应该适合您的情况。