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 Apr 17, 2014 1:09 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: glade-3.14.2 with treeview
PostPosted: Wed Oct 02, 2013 1:14 pm 
Offline

Joined: Sat Jul 27, 2013 7:54 pm
Posts: 3
Hi All,

i have a problem glade with treeview. i have created a treeview in glade with 3 columns as columns bellow

1. image
2. text
3. text

some more information i am using ubuntu 13.04 and gtk-3

when i am trying to add rows to the treeview using liststore i am facing the problem can someone help me. the code is as bellow

Code:
static void addMessageToTreeView(GtkListStore *store, GdkPixbuf *pbuf, const gchar *str, const gchar *str1)
{
    GtkTreeIter iter;


    gtk_list_store_append(store, &iter);
    gtk_list_store_set(store, &iter, 0, pbuf, 1, str, 2, str1, -1);
}

int
main (int argc, char *argv[])
{
    GtkBuilder      *builder;
    GtkWidget       *window;
    GtkListStore       *store;
    GtkWidget *list;
    GdkPixbuf *pbuf;

    GError     *error = NULL;

    gtk_init (&argc, &argv);

    builder = gtk_builder_new ();
    if(!gtk_builder_add_from_file (builder, "test12.glade", &error))
    {
        g_warning( "%s", error->message );
        g_free( error );
        return( 1 );
    }
    window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
    if(window == NULL)
    {
        fprintf(stdout,"error window\n");
        exit(0);
    }

    store = GTK_LIST_STORE (gtk_builder_get_object (builder, "liststore1"));
    if(store == NULL)
    {
        fprintf(stdout,"error store\n");
        exit(0);
    }


    pbuf = gtk_widget_render_icon_pixbuf (window, GTK_STOCK_DIALOG_INFO,  GTK_ICON_SIZE_DIALOG);

    addMessageToTreeView(store, pbuf, " text", "text1");
    g_object_unref (store);


    gtk_builder_connect_signals (builder, NULL);

    g_object_unref (G_OBJECT (builder));
    printf("This is small example for gtk\n");

    gtk_widget_show_all (window);
    gtk_main ();

    return 0;
}




and the glade file is bellow
Code:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <!-- interface-requires gtk+ 3.0 -->
  <object class="GtkListStore" id="liststore1">
    <columns>
      <!-- column-name image -->
      <column type="gchararray"/>
      <!-- column-name text -->
      <column type="gchar"/>
      <!-- column-name text1 -->
      <column type="gchar"/>
    </columns>
  </object>
  <object class="GtkWindow" id="window1">
    <property name="can_focus">False</property>
    <child>
      <object class="GtkBox" id="box1">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="orientation">vertical</property>
        <child>
          <placeholder/>
        </child>
        <child>
          <object class="GtkPaned" id="paned1">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="orientation">vertical</property>
            <child>
              <object class="GtkScrolledWindow" id="scrolledwindow1">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="shadow_type">in</property>
                <child>
                  <object class="GtkTreeView" id="treeview1">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="model">liststore1</property>
                    <child internal-child="selection">
                      <object class="GtkTreeSelection" id="treeview-selection1"/>
                    </child>
                    <child>
                      <object class="GtkTreeViewColumn" id="image">
                        <property name="title" translatable="yes">image</property>
                        <child>
                          <object class="GtkCellRendererPixbuf" id="imagecell"/>
                          <attributes>
                            <attribute name="pixbuf">0</attribute>
                          </attributes>
                        </child>
                      </object>
                    </child>
                    <child>
                      <object class="GtkTreeViewColumn" id="text">
                        <property name="title" translatable="yes">text</property>
                        <property name="expand">True</property>
                        <child>
                          <object class="GtkCellRendererText" id="textcell"/>
                          <attributes>
                            <attribute name="text">1</attribute>
                          </attributes>
                        </child>
                      </object>
                    </child>
                    <child>
                      <object class="GtkTreeViewColumn" id="time">
                        <property name="title" translatable="yes">time</property>
                        <child>
                          <object class="GtkCellRendererText" id="timecell"/>
                          <attributes>
                            <attribute name="text">2</attribute>
                          </attributes>
                        </child>
                      </object>
                    </child>
                  </object>
                </child>
              </object>
              <packing>
                <property name="resize">False</property>
                <property name="shrink">True</property>
              </packing>
            </child>
            <child>
              <object class="GtkButton" id="button1">
                <property name="label" translatable="yes">button</property>
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="receives_default">True</property>
              </object>
              <packing>
                <property name="resize">True</property>
                <property name="shrink">True</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="expand">True</property>
            <property name="fill">True</property>
            <property name="position">1</property>
          </packing>
        </child>
        <child>
          <placeholder/>
        </child>
      </object>
    </child>
  </object>
</interface>




Thanks in advance


Top
 Profile  
 
 Post subject: Re: glade-3.14.2 with treeview
PostPosted: Wed Oct 02, 2013 3:17 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 709
Location: UK
Hello,

You say that you have a problem, but you have so far not said what it is so that we can help. If you can give more information on the problem and what you want that would help.

_________________
E.


Top
 Profile  
 
 Post subject: Re: glade-3.14.2 with treeview
PostPosted: Wed Oct 02, 2013 5:23 pm 
Offline

Joined: Sat Jul 27, 2013 7:54 pm
Posts: 3
hi errol,

sorry for not giving the error what i am getting. i have mentioned the error below now and please help me if it can bel possible by you.

(a.out:2764): Gtk-CRITICAL **: gtk_tree_model_get_iter: assertion `GTK_IS_TREE_MODEL (tree_model)' failed

(a.out:2764): Gtk-CRITICAL **: gtk_cell_area_apply_attributes: assertion `GTK_IS_TREE_MODEL (tree_model)' failed

(a.out:2764): Gtk-CRITICAL **: gtk_cell_area_apply_attributes: assertion `GTK_IS_TREE_MODEL (tree_model)' failed
Segmentation fault (core dumped)


i could not able to trace where exactly the error is comming. when i did gdb i got the segmentation fault in gtk_widget_show_all.

Thanks
Rabi


Top
 Profile  
 
 Post subject: Re: glade-3.14.2 with treeview
PostPosted: Sun Oct 06, 2013 1:31 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 709
Location: UK
Below is the correction of your code.

What you have done is set the incorrect type for your image in the GtkListStore in your Glade file. You initially specified it as gustring when it should be GdkPixbuf.

Another thing to note is that GtkBox is now deprecated in GTK v3. This I have corrected by using GtkGrid in the Glade file.

Code:
#include <gtk/gtk.h>
#include <stdio.h>
#include <stdlib.h>

static void addMessageToTreeView(GtkListStore *store, GdkPixbuf *pbuf, const gchar *str, const gchar *str1)
{
    GtkTreeIter iter;


    gtk_list_store_append(store, &iter);
    gtk_list_store_set(store, &iter, 0, pbuf, 1, str, 2, str1, -1);
}

int
main (int argc, char *argv[])
{
    GtkBuilder      *builder;
    GtkWidget       *window;
    GtkListStore       *store;
    GtkWidget *list;
    GdkPixbuf *pbuf;

    GError     *error = NULL;

    gtk_init (&argc, &argv);

    builder = gtk_builder_new ();
    if(!gtk_builder_add_from_file (builder, "test12.glade", &error))
    {
        g_warning( "%s", error->message );
        g_free( error );
        return( 1 );
    }
    window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
    if(window == NULL)
    {
        fprintf(stdout,"error window\n");
        exit(0);
    }

    store = GTK_LIST_STORE (gtk_builder_get_object (builder, "liststore1"));
    if(store == NULL)
    {
        fprintf(stdout,"error store\n");
        exit(0);
    }


    pbuf = gtk_widget_render_icon_pixbuf (window, GTK_STOCK_DIALOG_INFO,  GTK_ICON_SIZE_DIALOG);

    addMessageToTreeView(store, pbuf, " text", "text1");
    //g_object_unref (store);


    gtk_builder_connect_signals (builder, NULL);

    g_object_unref (G_OBJECT (builder));
    printf("This is small example for gtk\n");

    gtk_widget_show_all (window);
    gtk_main ();

    return 0;
}

Code:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <!-- interface-requires gtk+ 3.0 -->
  <object class="GtkListStore" id="liststore1">
    <columns>
      <!-- column-name image -->
      <column type="GdkPixbuf"/>
      <!-- column-name text -->
      <column type="gchar"/>
      <!-- column-name text1 -->
      <column type="gchar"/>
    </columns>
  </object>
  <object class="GtkWindow" id="window1">
    <property name="can_focus">False</property>
    <child>
      <object class="GtkGrid" id="grid1">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <child>
          <object class="GtkPaned" id="paned1">
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="hexpand">True</property>
            <property name="vexpand">True</property>
            <property name="orientation">vertical</property>
            <child>
              <object class="GtkScrolledWindow" id="scrolledwindow1">
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="shadow_type">in</property>
                <child>
                  <object class="GtkTreeView" id="treeview1">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="model">liststore1</property>
                    <property name="headers_clickable">False</property>
                    <property name="search_column">1</property>
                    <child internal-child="selection">
                      <object class="GtkTreeSelection" id="treeview-selection"/>
                    </child>
                    <child>
                      <object class="GtkTreeViewColumn" id="image">
                        <property name="title" translatable="yes">image</property>
                        <child>
                          <object class="GtkCellRendererPixbuf" id="imagecell"/>
                          <attributes>
                            <attribute name="pixbuf">0</attribute>
                          </attributes>
                        </child>
                      </object>
                    </child>
                    <child>
                      <object class="GtkTreeViewColumn" id="text">
                        <property name="title" translatable="yes">text</property>
                        <property name="expand">True</property>
                        <child>
                          <object class="GtkCellRendererText" id="textcell"/>
                          <attributes>
                            <attribute name="text">1</attribute>
                          </attributes>
                        </child>
                      </object>
                    </child>
                    <child>
                      <object class="GtkTreeViewColumn" id="time">
                        <property name="title" translatable="yes">time</property>
                        <child>
                          <object class="GtkCellRendererText" id="timecell"/>
                          <attributes>
                            <attribute name="text">2</attribute>
                          </attributes>
                        </child>
                      </object>
                    </child>
                  </object>
                </child>
              </object>
              <packing>
                <property name="resize">True</property>
                <property name="shrink">True</property>
              </packing>
            </child>
            <child>
              <object class="GtkButton" id="button1">
                <property name="label" translatable="yes">button</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
              </object>
              <packing>
                <property name="resize">True</property>
                <property name="shrink">True</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="left_attach">0</property>
            <property name="top_attach">0</property>
            <property name="width">1</property>
            <property name="height">1</property>
          </packing>
        </child>
        <child>
          <placeholder/>
        </child>
      </object>
    </child>
  </object>
</interface>

_________________
E.


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

All times are UTC


Who is online

Users browsing this forum: No registered users 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