我如何用GTK3在C中调用另一个“窗口”

时间:2023-01-24 16:16:24

i want to call another window when i press the button "on_btn_janelaCriarSessao_clicked", my code of the window is this:

当我按下“on_btn_janelaCriarSessao_clicked”按钮时,我想调用另一个窗口,我的窗口代码是这样的:

JanelaCriarSessao::JanelaCriarSessao(){
/* JANELA CRIAR SESSAO */

windowCriarSessao = gtk_window_new(GTK_WINDOW_TOPLEVEL);
//
gtk_window_set_default_size(GTK_WINDOW(windowCriarSessao), 400, 250);
gtk_window_set_title(GTK_WINDOW(windowCriarSessao), "Criar Sessao");
gtk_window_set_position(GTK_WINDOW(windowCriarSessao), GTK_WIN_POS_CENTER_ALWAYS);
gtk_window_set_resizable(GTK_WINDOW(windowCriarSessao), FALSE);

textoInformativo = gtk_label_new("Digite a chave(ID) da sessao abaixo: ");
entry_IDSESSAO = gtk_entry_new ();
btn_cadastrarSessao = gtk_button_new_with_label("Cadastrar");

caixaWidgets = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);

//empacotamento dos widgets na janela
gtk_box_pack_start(GTK_BOX(caixaWidgets), textoInformativo, TRUE, TRUE, 3);
gtk_box_pack_start(GTK_BOX(caixaWidgets), entry_IDSESSAO, TRUE, TRUE, 3);
gtk_box_pack_end(GTK_BOX(caixaWidgets), btn_cadastrarSessao, TRUE, TRUE, 3);

g_signal_connect (GTK_ENTRY(entry_IDSESSAO), "activate", 
    G_CALLBACK(entry_activate), textoInformativo);

//Connects GCallback function gtk_main_quit to "destroy" signal for "window"
g_signal_connect(G_OBJECT(windowCriarSessao), "destroy", 
    G_CALLBACK(gtk_main_quit), NULL);

gtk_container_add(GTK_CONTAINER(windowCriarSessao), caixaWidgets);}

and the code of button is this:

而按钮的代码是这样的:

void JanelaPrincipal::mostrar(){
//mostra a janela principal
gtk_widget_show_all(window);} 
void on_btn_janelaCriarSessao_clicked(GtkWidget *widget, JanelaPrincipal *data){ JanelaCriarSessao obj;
obj.mostrar();}

But, when i press the button, he open the window but without any widget, a blank Window just with the title i put in. The code of my main.cpp:

但是,当我按下按钮时,他打开窗口,但没有任何小部件,一个空白的窗口,只有我输入的标题。我的main.cpp的代码:

gtk_init(&argc, &argv);

JanelaPrincipal obj;
obj.mostrar();

gtk_main();

return 0;}

1 个解决方案

#1


0  

btn_cadastrarSessao = gtk_button_new_with_label("Cadastrar");

I believe the connection to the clicked event is missing:

我相信缺少与点击事件的连接:

g_signal_connect(G_OBJECT(btn_cadastrarSessao), "clicked", ...

#1


0  

btn_cadastrarSessao = gtk_button_new_with_label("Cadastrar");

I believe the connection to the clicked event is missing:

我相信缺少与点击事件的连接:

g_signal_connect(G_OBJECT(btn_cadastrarSessao), "clicked", ...