GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Oct 23, 2014 8:41 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: assertion 'gtk is widget(widget)' failed
PostPosted: Tue Nov 22, 2011 8:10 pm 
Offline

Joined: Tue Nov 22, 2011 5:48 pm
Posts: 2
Hello, I have some problem to run a simple window with glade and gtk+ under windows 7:

When I want to start it, I get this error message: Gtk-CRITICAL **: gtk_widget_show: assertion 'GTK_IS_WIDGET(widget)' failed.

The source code (from a tutorial):
Code:
#ifdef WIN32
#include <windows.h>
#endif
#include <stdlib.h>
#include <gtk/gtk.h>

void
on_window_destroy (GtkObject *object, gpointer user_data)
{
    gtk_main_quit ();
}

int
main (int argc, char *argv[])
{
    GtkBuilder      *builder;
    GtkWidget       *window;

    gtk_init (&argc, &argv);

    builder = gtk_builder_new ();
    gtk_builder_add_from_file (builder, "ui.glade", NULL);
    window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
    gtk_builder_connect_signals (builder, NULL);

    g_object_unref (G_OBJECT (builder));

    gtk_widget_show (window);
    gtk_main ();

    return 0;
}


And the glade file:
Code:
<?xml version="1.0"?>
<interface>
  <requires lib="gtk+" version="2.14"/>
  <!-- interface-naming-policy project-wide -->
  <object class="GtkWindow" id="window">
    <signal name="destroy" handler="on_window_destroy"/>
    <child>
      <object class="GtkLabel" id="label1">
        <property name="visible">True</property>
        <property name="label" translatable="yes">hello world!</property>
      </object>
    </child>
  </object>
</interface>


any idea ?


Top
 Profile  
 
 Post subject: Re: assertion 'gtk is widget(widget)' failed
PostPosted: Wed Nov 23, 2011 5:40 am 
Offline
GTK+ Guru

Joined: Sun Apr 06, 2008 6:43 pm
Posts: 286
Location: Fortress of solitude
In Windows environment, I have two options:

1.- The UI file isn't loaded.
2.- I have my doubts using glade/buiilder in windows, because you need to pass a flag in gcc: -export-dynamic, there's a workaround for windows users: http://lists.ximian.com/pipermail/glade ... 02301.html, this in case that you are not using gcc or migw32.
3.- Tip, since you are in Windows, use glib's macro:
Code:
#include <gtk/gtk.h> // gtk calls glib's headers
#ifdef G_OS_WIN32
#include <windows.h>
#endif

_________________
* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
* Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.


Top
 Profile  
 
 Post subject: Re: assertion 'gtk is widget(widget)' failed
PostPosted: Wed Nov 23, 2011 5:19 pm 
Offline

Joined: Tue Nov 22, 2011 5:48 pm
Posts: 2
Yeah the UI file is the problem I think because:

this tutorial xml works:
Code:
<?xml version="1.0" ?><!--Generated with glade3 3.4.0 on Tue Nov 20 14:05:37 2007 --><interface>
  <object class="GtkWindow" id="window1">
    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
    <child>
      <placeholder/>
    </child>
  </object>
</interface>

But my self build file dont work:
Code:
<?xml version="1.0"?>
<interface>
  <requires lib="gtk+" version="2.14"/>
  <!-- interface-naming-policy project-wide -->
  <object class="GtkWindow" id="window1">
    <signal name="destroy" handler="on_window_destroy"/>
    <child>
      <object class="GtkLabel" id="label1">
        <property name="visible">True</property>
        <property name="label" translatable="yes">hello world!</property>
      </object>
    </child>
  </object>
</interface>


Forgotten to say, I am using code:blocks with the minGW gcc compiler. I have added the flags you have posted but with no effect. I still get this
error message :(

Edit:
Found the problem: I deleted this "<requires lib="gtk+" version="2.14"/>" from the glade file, now it runs.

:)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot], Google Adsense [Bot] and 2 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