GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Aug 27, 2016 9:53 am

All times are UTC

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Multi Page Program (Solved)
PostPosted: Sat Feb 16, 2008 9:06 pm 
Familiar Face

Joined: Thu Jan 31, 2008 11:34 pm
Posts: 5
hi, i newby

i´m haven a problem to try to do a multi page dialog.

i can do it forward, but no goback;

it show a mensage erro in debugger:
<LabCel.exe:3576>: Gtk-CRITICAL **: gtk_box_pack_start: assertion `GTK_IS_WIDGET <child>´ failed

my .c is
#include <stdlib.h>
#include <gtk/gtk.h>

static void button_forward (GtkWidget *widget, gpointer data);
static void button_back_ (GtkWidget *widget, gpointer data);
typedef struct
    GtkWidget *widget;
    GtkWidget *title;

gint i=0;

GtkWidget *button_back = NULL;
GtkWidget *button_fwrd = NULL;
GtkWidget *window = NULL;
GtkWidget *button_box = NULL;
GtkWidget *win_page = NULL;
GtkWidget *aula_box = NULL;
GtkWidget *page[8];

int main (int argc, char *argv[])

    /* Initialize GTK+ */
    gtk_init (&argc, &argv);

    /* Create the main window */
        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        gtk_container_set_border_width (GTK_CONTAINER (window), 10);
        gtk_window_set_title (GTK_WINDOW (window), "LabCel 1.0");
        gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
        gtk_widget_set_size_request(window, 200, 200);
        g_signal_connect (window, "destroy", gtk_main_quit, NULL);

    win_page = gtk_vbox_new (FALSE, 10);

    aula_box = gtk_vbox_new (FALSE,0);
    page[0] = gtk_label_new ("MENU");
    page[1] = gtk_label_new ("TESTE1");
    page[2] = gtk_label_new ("TESTE2");
    page[3] = gtk_label_new ("TESTE3");
    page[4] = gtk_label_new ("TESTE4");
    page[5] = gtk_label_new ("TESTE5");
    page[6] = gtk_label_new ("TESTE6");
    page[7] = gtk_label_new ("TESTE7");
    gtk_box_pack_start (GTK_BOX(aula_box),page[0],FALSE,FALSE,2);

    gtk_box_pack_start_defaults (GTK_BOX(win_page), aula_box);

    /* Create a Horizontal box with buttons */

    button_box = gtk_hbox_new (FALSE, 6);

    button_fwrd = gtk_button_new_with_mnemonic ("_Avancar");
    gtk_box_pack_end (GTK_BOX (button_box), button_fwrd, FALSE,TRUE,0);
    gtk_widget_set_size_request (button_fwrd,58,-1);
    g_signal_connect (G_OBJECT (button_fwrd), "clicked",G_CALLBACK (button_forward),NULL);

    button_back = gtk_button_new_with_mnemonic ("_Voltar");
    gtk_box_pack_end (GTK_BOX (button_box), button_back, FALSE,TRUE,0);
    gtk_widget_set_size_request (button_back,58,-1);
    g_signal_connect (G_OBJECT (button_back), "clicked",G_CALLBACK (button_back_),NULL);

    gtk_box_pack_start(GTK_BOX (win_page), button_box,FALSE, FALSE,0);

    gtk_container_add (GTK_CONTAINER (window),win_page);

    /* Enter the main loop */
    gtk_widget_show_all (window);
    gtk_main ();

    return 0;

static void button_forward (GtkWidget *widget, gpointer data)
    if (i<7)
        gtk_container_remove (aula_box,page[i]);
        gtk_box_pack_start (GTK_BOX(aula_box),page[i],FALSE,FALSE,2);
        gtk_widget_show_all (aula_box);

static void button_back_ (GtkWidget *widget, gpointer data)
    if (i>0)
        gtk_widget_hide_all (page[i]);
        //gtk_container_remove (aula_box,page[i]);
        gtk_box_pack_start (GTK_BOX(aula_box),page[i],FALSE,FALSE,2);
        gtk_widget_show_all (aula_box);

 Post subject:
PostPosted: Sat Mar 08, 2008 5:05 am 
Familiar Face

Joined: Thu Jan 31, 2008 11:34 pm
Posts: 5
Giving a look at the documentation of the library, I found something very interesting. When gtk_container_remove is used, gtk eliminates the widget of the container and memory because of this, I could not add back in the container button_back when pressed, because the gtk not find it on any side. To solve it we must use a reference to g_object_ref.

maybe this is not news to nobody, and I am speaking shit, but doing what, do you not?

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC

Who is online

Users browsing this forum: Google Adsense [Bot] and 3 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group