2011-08-13 6 views
0

Glade-3を使用しています。その後Gtkでエラーを取得しています。どういう理由ですか?

<?xml version="1.0"?> 
<interface> 
    <requires lib="gtk+" version="2.16"/> 
    <!-- interface-naming-policy project-wide --> 
    <object class="GtkListStore" id="liststore1"/> 
    <object class="GtkWindow" id="Home"> 
    <property name="destroy_with_parent">True</property> 
    <signal name="destroy" handler="gtk_main_quit"/> 
    <child> 
     <object class="GtkVBox" id="vbox1"> 
     <property name="visible">True</property> 
     <property name="orientation">vertical</property> 
     <child> 
      <object class="GtkHBox" id="hbox1"> 
      <property name="visible">True</property> 
      <child> 
       <object class="GtkScrolledWindow" id="scrolledwindow1"> 
       <property name="visible">True</property> 
       <property name="can_focus">True</property> 
       <property name="hscrollbar_policy">automatic</property> 
       <property name="vscrollbar_policy">automatic</property> 
       <child> 
        <object class="GtkTreeView" id="treeview2"> 
        <property name="visible">True</property> 
        <property name="can_focus">True</property> 
        <property name="model">liststore1</property> 
        </object> 
       </child> 
       </object> 
       <packing> 
       <property name="position">0</property> 
       </packing> 
      </child> 
      <child> 
       <object class="GtkVButtonBox" id="vbuttonbox2"> 
       <property name="visible">True</property> 
       <property name="orientation">vertical</property> 
       <property name="spacing">2</property> 
       <property name="layout_style">center</property> 
       <child> 
        <object class="GtkButton" id="button1"> 
        <property name="label">gtk-goto-top</property> 
        <property name="visible">True</property> 
        <property name="can_focus">True</property> 
        <property name="receives_default">True</property> 
        <property name="use_stock">True</property> 
        </object> 
        <packing> 
        <property name="expand">False</property> 
        <property name="fill">False</property> 
        <property name="position">0</property> 
        </packing> 
       </child> 
       <child> 
        <object class="GtkButton" id="button2"> 
        <property name="label">gtk-go-up</property> 
        <property name="visible">True</property> 
        <property name="can_focus">True</property> 
        <property name="receives_default">True</property> 
        <property name="use_stock">True</property> 
        </object> 
        <packing> 
        <property name="expand">False</property> 
        <property name="fill">False</property> 
        <property name="position">1</property> 
        </packing> 
       </child> 
       <child> 
        <object class="GtkButton" id="button3"> 
        <property name="label">gtk-add</property> 
        <property name="visible">True</property> 
        <property name="can_focus">True</property> 
        <property name="receives_default">True</property> 
        <property name="use_stock">True</property> 
        </object> 
        <packing> 
        <property name="expand">False</property> 
        <property name="fill">False</property> 
        <property name="position">2</property> 
        </packing> 
       </child> 
       <child> 
        <object class="GtkButton" id="button4"> 
        <property name="label">gtk-remove</property> 
        <property name="visible">True</property> 
        <property name="can_focus">True</property> 
        <property name="receives_default">True</property> 
        <property name="use_stock">True</property> 
        </object> 
        <packing> 
        <property name="expand">False</property> 
        <property name="fill">False</property> 
        <property name="position">3</property> 
        </packing> 
       </child> 
       <child> 
        <object class="GtkButton" id="button5"> 
        <property name="label">gtk-go-down</property> 
        <property name="visible">True</property> 
        <property name="can_focus">True</property> 
        <property name="receives_default">True</property> 
        <property name="use_stock">True</property> 
        </object> 
        <packing> 
        <property name="expand">False</property> 
        <property name="fill">False</property> 
        <property name="position">4</property> 
        </packing> 
       </child> 
       <child> 
        <object class="GtkButton" id="button6"> 
        <property name="label">gtk-goto-bottom</property> 
        <property name="visible">True</property> 
        <property name="can_focus">True</property> 
        <property name="receives_default">True</property> 
        <property name="use_stock">True</property> 
        </object> 
        <packing> 
        <property name="expand">False</property> 
        <property name="fill">False</property> 
        <property name="position">5</property> 
        </packing> 
       </child> 
       </object> 
       <packing> 
       <property name="position">1</property> 
       </packing> 
      </child> 
      <child> 
       <object class="GtkVBox" id="vbox2"> 
       <property name="visible">True</property> 
       <property name="orientation">vertical</property> 
       <child> 
        <object class="GtkViewport" id="viewport1"> 
        <property name="visible">True</property> 
        <property name="resize_mode">queue</property> 
        <child> 
         <object class="GtkAlignment" id="alignment1"> 
         <property name="width_request">0</property> 
         <property name="height_request">0</property> 
         <property name="visible">True</property> 
         <property name="xscale">0</property> 
         <property name="yscale">0</property> 
         <child> 
          <object class="GtkFrame" id="frame1"> 
          <property name="visible">True</property> 
          <property name="label_xalign">0</property> 
          <property name="shadow_type">in</property> 
          <child> 
           <object class="GtkDrawingArea" id="drawingarea1"> 
           <property name="width_request">300</property> 
           <property name="height_request">200</property> 
           <property name="visible">True</property> 
           </object> 
          </child> 
          <child type="label_item"> 
           <placeholder/> 
          </child> 
          </object> 
         </child> 
         </object> 
        </child> 
        </object> 
        <packing> 
        <property name="position">0</property> 
        </packing> 
       </child> 
       <child> 
        <object class="GtkHButtonBox" id="hbuttonbox1"> 
        <property name="visible">True</property> 
        <property name="spacing">2</property> 
        <property name="homogeneous">True</property> 
        <property name="layout_style">center</property> 
        <child> 
         <object class="GtkCheckButton" id="checkbutton2"> 
         <property name="label" translatable="yes">Show points</property> 
         <property name="visible">True</property> 
         <property name="can_focus">True</property> 
         <property name="receives_default">False</property> 
         <property name="draw_indicator">True</property> 
         </object> 
         <packing> 
         <property name="expand">False</property> 
         <property name="fill">False</property> 
         <property name="position">0</property> 
         </packing> 
        </child> 
        <child> 
         <object class="GtkCheckButton" id="checkbutton1"> 
         <property name="label" translatable="yes">Show lines</property> 
         <property name="visible">True</property> 
         <property name="can_focus">True</property> 
         <property name="receives_default">False</property> 
         <property name="draw_indicator">True</property> 
         </object> 
         <packing> 
         <property name="expand">False</property> 
         <property name="fill">False</property> 
         <property name="position">1</property> 
         </packing> 
        </child> 
        </object> 
        <packing> 
        <property name="expand">False</property> 
        <property name="position">1</property> 
        </packing> 
       </child> 
       </object> 
       <packing> 
       <property name="position">2</property> 
       </packing> 
      </child> 
      </object> 
      <packing> 
      <property name="position">1</property> 
      </packing> 
     </child> 
     <child> 
      <object class="GtkStatusbar" id="statusbar1"> 
      <property name="visible">True</property> 
      <property name="spacing">2</property> 
      </object> 
      <packing> 
      <property name="expand">False</property> 
      <property name="pack_type">end</property> 
      <property name="position">0</property> 
      </packing> 
     </child> 
     </object> 
    </child> 
    </object> 
</interface> 

私はtut.cという名前のCプログラムを作った:私は名前tut.gladeでプロジェクトを保存し、テキストエディタでファイルを開いたenter image description here

、ここでのコードがあります:私はこのツールを作りました私はその後、コンパイル

#include <gtk/gtk.h> 

int 
main(int argc, 
     char **argv) 
{ 
    GtkBuilder *builder; 
    GtkWidget *window; 
    GError  *error = NULL; 

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

    /* Create new GtkBuilder object */ 
    builder = gtk_builder_new(); 
    /* Load UI from file. If error occurs, report it and quit application. 
*  * Replace "tut.glade" with your saved project. */ 
    if(! gtk_builder_add_from_file(builder, "tut.glade", &error)) 
    { 
     g_warning("%s", error->message); 
     g_free(error); 
     return(1); 
    } 

    /* Get main window pointer from UI */ 
    window = GTK_WIDGET(gtk_builder_get_object(builder, "window1")); 

    /* Connect signals */ 
    gtk_builder_connect_signals(builder, NULL); 

    /* Destroy builder, since we don't need it anymore */ 
    g_object_unref(G_OBJECT(builder)); 

    /* Show window. All other widgets are automatically shown by GtkBuilder */ 
    gtk_widget_show(window); 

    /* Start main loop */ 
    gtk_main(); 

    return(0); 
} 

それは

を使用して次のコードを持っていますgcc -o tut tut.c $(pkg-config --cflags --libs gtk+-2.0 gmodule-2.0)

tutという実行可能ファイルがあります。私は

./tut

を使用してそれを実行し、私はこのエラーました:あなたは"window1"という名前のオブジェクトのために求めているが、そのようなものは、あなたのtut.gladeファイルではありません

(tut:19516): Gtk-CRITICAL **: gtk_widget_show: assertion `GTK_IS_WIDGET (widget)' failed 
+1

'g_free'ではなく' g_error_free'を使ってエラーを解決してください! – ptomato

答えて

3

を。唯一のウィンドウがXMLにあります:

<object class="GtkWindow" id="Home"> 

ので、この交換してみてください。これで

window = GTK_WIDGET(gtk_builder_get_object(builder, "window1")); 

window = GTK_WIDGET(gtk_builder_get_object(builder, "Home")); 

をそして多分window上のNULLチェックがあまりにも良いでしょう。

+0

おっと!愚かな間違い。 –

+0

@Chankey:時にはそれは明白な目を見て新鮮な目を取る:) –

+0

はい:)ねえ、私は1つのことを聞きたいです。 PerlでCで作成したのと同じコードを作成できますか? –

関連する問題