GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Apr 23, 2014 6:46 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: glade!?
PostPosted: Tue Nov 06, 2007 2:05 pm 
Offline
Familiar Face

Joined: Fri Sep 28, 2007 10:59 am
Posts: 46
I want to run the program which i wrote with glade . but it send error could not find signal handler 'hamid' . while I wrote call back function. what is the problem
If I give the file extension c , it will be compile and run completely . but if i give it cpp , at runtime give me this alert could not find signal handler 'hamid' and does not run correctly . in order to compile the file with cpp extension what should i do?
Code:
#include <gtk/gtk.h>
#include <glade/glade.h>
GladeXML *xml;
void hamid(GtkWidget *widget, gpointer user_data) {
GtkWidget *dialog;
dialog=glade_xml_get_widget(xml, "dialog");
gtk_widget_show_all(dialog);
}

int main(int argc , char *argv[] ) {
gtk_init( &argc , &argv);
GtkWidget  *window ;
xml = glade_xml_new("a.glade", NULL, NULL);
window= glade_xml_get_widget(xml, "window");
glade_xml_signal_autoconnect(xml);
gtk_widget_show_all(window);
gtk_main();
return 0;
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 06, 2007 3:35 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
When using the glade_xml_signal_autoconnect function, you need to use the
Code:
--export-dynamic
linker flag.

For example:

Code:
cc -Wall -g --export-dynamic -o example `pkg-config --cflags --libs gtk+-2.0 libglade-2.0` example.c

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 06, 2007 6:24 pm 
Offline
Familiar Face

Joined: Fri Sep 28, 2007 10:59 am
Posts: 46
I used the command but it didnt solve.
when the file extension is cpp this problem exists but there is no problem with C . pealse test ...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 06, 2007 7:31 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
Sorry, it's like this:

Code:
g++ -Wall -g -export-dynamic -o test `pkg-config --cflags --libs gtk+-2.0 libglade-2.0` test.cpp


I tested it and it worked with this glade file:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.0 on Tue Nov  6 11:30:36 2007 -->
<glade-interface>
  <widget class="GtkWindow" id="window">
    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
    <signal name="destroy" handler="gtk_main_quit"/>
    <child>
      <placeholder/>
    </child>
  </widget>
</glade-interface>

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 21, 2007 4:02 am 
Offline
Familiar Face

Joined: Fri Sep 28, 2007 10:59 am
Posts: 46
See the following program . if we have callback function in the program and file extention be cpp at run tim we recive the massage that it cant recognize call back function
examp.cpp

Code:
#include <gtk/gtk.h>
#include <glade/glade.h>
void on_button1_clicked(GtkWidget *widget, gpointer user_data)
{
g_print("Button 1 Clicked");
}

void on_button2_clicked(GtkWidget *widget, gpointer user_data) {
g_print("Button 2 Clicked");
}
int main(int argc, char *argv[]) {
    GladeXML *xml;
    GtkWidget *window;
    gtk_init(&argc, &argv);
    xml = glade_xml_new("examp.glade",NULL, NULL);
    window=glade_xml_get_widget(xml,"window");
    glade_xml_signal_autoconnect(xml);
    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}


examp.glade
Code:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.0 on Wed Nov 21 19:47:30 2007 -->
<glade-interface>
  <widget class="GtkWindow" id="window">
    <property name="width_request">250</property>
    <property name="height_request">250</property>
    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
    <property name="border_width">15</property>
    <signal name="delete_event" handler="gtk_main_quit"/>
    <child>
      <widget class="GtkVBox" id="vbox">
        <property name="visible">True</property>
        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
        <child>
          <widget class="GtkLabel" id="label">
            <property name="visible">True</property>
            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
            <property name="label" translatable="yes">GNOME User Interface </property>
          </widget>
        </child>
        <child>
          <widget class="GtkHBox" id="hbox">
            <property name="visible">True</property>
            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
            <child>
              <widget class="GtkButton" id="button1">
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                <property name="border_width">13</property>
                <property name="label" translatable="yes">button one</property>
                <property name="response_id">0</property>
                <signal name="clicked" handler="on_button1_clicked" object="NULL"/>
              </widget>
            </child>
            <child>
              <widget class="GtkButton" id="button2">
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                <property name="border_width">13</property>
                <property name="label" translatable="yes">button two</property>
                <property name="response_id">0</property>
                <signal name="clicked" handler="on_button2_clicked"/>
              </widget>
              <packing>
                <property name="position">1</property>
              </packing>
            </child>
          </widget>
          <packing>
            <property name="position">1</property>
          </packing>
        </child>
      </widget>
    </child>
  </widget>
</glade-interface>



Code:
linux-fotc:~ # g++ -export-dynamic `pkg-config  --cflags  --libs gtk+-2.0` `pkg-config  --cflags  --libs libglade-2.0 ` examp.cpp -o examp
linux-fotc:~ # ./examp

(examp:3871): libglade-WARNING **: could not find signal handler 'on_button2_clicked'.

(examp:3871): libglade-WARNING **: could not find signal handler 'on_button1_clicked'.

...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 21, 2007 6:16 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
I have learned that C++ compiler mangles symbol names to support it's various features (function overloading). Therefore, to get libglade to be able to locate your symbol, you can add 'extern "C"' before the function definition.

So, to get libglade's glade_xml_signal_autoconnect function to work with a C++ compiler, you need to both use extern "C" as well as the -export-dynamic linker flag.

This code works:

Code:
#include <gtk/gtk.h>
#include <glade/glade.h>
extern "C" void on_button1_clicked(GtkWidget *widget, gpointer user_data)
{
g_print("Button 1 Clicked");
}

extern "C" void on_button2_clicked(GtkWidget *widget, gpointer user_data) {
g_print("Button 2 Clicked");
}
int main(int argc, char *argv[]) {
    GladeXML *xml;
    GtkWidget *window;
    gtk_init(&argc, &argv);
    xml = glade_xml_new("examp.glade",NULL, NULL);
    window=glade_xml_get_widget(xml,"window");
    glade_xml_signal_autoconnect(xml);
    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}


Keep in mind that this is all related to the autoconnect function. You can still use the regular glade_xml_signal_connect function without all this jazz. Plus, the autoconnect function will not allow you to pass objects as user_data other than widgets within the glade file.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


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

All times are UTC


Who is online

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