我已经对我的问题进行了一些深入的研究,但仍然想不通它的来源,因此希望有人可以帮助我。
我最近开始使用gtk,Glade和C创建一个带有图形界面的小程序的项目,但问题是:我无法更改在单击时弹出的窗口中显示的标签在按钮上。
这是我的Glade语言学观点,与与按钮相关的信号称为
interface on Glade for the window that pops up
callbacks to functions in my gtk functions c file from glade
在第二张图片中,“ clicked”事件的回调位于另一个窗口的按钮上,有4个回调
这是我的带有gtk函数的C文件
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
int new_window(char * window_to_build) {
GtkBuilder * builder;
GError * error = NULL;
GtkWidget *window;
builder = gtk_builder_new();
if (gtk_builder_add_from_file(builder, "interface.glade", &error) == 0){
g_printerr ("%s\n", error->message);
g_clear_error (&error);
system("pause");
return 1;
}
window = GTK_WIDGET(gtk_builder_get_object (builder, window_to_build));
gtk_builder_connect_signals(builder, NULL);
gtk_widget_show(window);
return 0;
}
int interface(int argc, char **argv){
gtk_init (&argc, &argv);
if (new_window("startup_window") == 1)
return 1;
gtk_main ();
return 0;
}
G_MODULE_EXPORT void login_button_clicked(GtkButton *button, gpointer user_data){
gtk_widget_hide(GTK_WIDGET(user_data));
if (new_window("login_window") == 1)
exit(EXIT_FAILURE);
}
G_MODULE_EXPORT void signup_button_clicked(GtkButton * button, gpointer user_data){
gtk_widget_hide(GTK_WIDGET(user_data));
if (new_window("signup_window") == 1)
exit(EXIT_FAILURE);
}
G_MODULE_EXPORT void return_button_clicked (GtkButton * button, gpointer user_data) {
gtk_widget_hide(GTK_WIDGET(user_data));
if (new_window("startup_window") == 1)
exit(EXIT_FAILURE);
}
G_MODULE_EXPORT void validate_button_clicked (GtkButton * button, gpointer user_data) {
gtk_widget_hide(GTK_WIDGET(user_data));
if (new_window("main_window") == 1)
exit(EXIT_FAILURE);
}
G_MODULE_EXPORT void user_info_button_clicked (GtkButton * button, gpointer user_data) {
if (new_window("user_information_window") == 1)
exit(EXIT_FAILURE);
}
G_MODULE_EXPORT void change_user_name_label (GtkButton * button, GtkLabel * name_label) {
g_print("%s\n", gtk_label_get_text(name_label));
gtk_label_set_text(name_label, "You clicked the button!");
}
G_MODULE_EXPORT void change_user_pseudo_label (GtkButton * button, GtkLabel * pseudo_label) {
gtk_label_set_text(pseudo_label, "You clicked the button!");
}
G_MODULE_EXPORT void change_user_mail_label (GtkButton * button, GtkLabel * mail_label) {
gtk_label_set_text(mail_label, "You clicked the button!");
}
我的第一个回调函数有一个g_print,它应该更改当前的标签“ text”,并显示它。
这是我的主文件,带有构建器的初始调用
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include "headers.h"
int main (int argc, char ** argv){
if (interface(argc, argv) == 1)
return EXIT_FAILURE;
return EXIT_SUCCESS;
}
这是我的头文件
#ifndef HEADERS_H_INCLUDED
#define HEADERS_H_INCLUDED
int interface(int, char **);
G_MODULE_EXPORT void login_button_clicked(GtkButton*, gpointer);
G_MODULE_EXPORT void signup_button_clicked(GtkButton*, gpointer, GtkWidget *);
#endif // HEADERS_H_INCLUDED
因此,当我打开该窗口时,应该更改“文本”标签,但是没有一个?