Re: Signals & Callbacks - Help!! Part 2

jalkadir gosonic ca wrote:

I am not an expert in GLIB, but, following your suggestion, I have added
the following variables. Notice that it is similar to the one in your
gchar strMsg;

Should be gchar *strMsg;

strMsg = g_strdup("Under Comstruction ... ");

However, this statement gives me an error that reads:

main.cpp: In function `int main(int, char**)':

main.cpp:25: error: invalid conversion from `gchar*' to `gchar'
main.cpp:83: error: invalid conversion from `gchar' to `void*'
main.cpp:83: error:   initializing argument 1 of `void g_free(void*)'

make.exe: *** [main.o] Error 1

Execution terminated

What am I doing wrong?

jalkadir gosonic ca ha scritto lo scorso 09/07/2005 02:28:
Thank Yeti for your help, I really appreciate your input. However, due
my lack of experience on GTK+ I am afraid I would need something a bit
more tangible. Could you please provide me with a example or point me to
to a place where I could find examples of GTK+ software?

Thanks in advance.
Maybe this can help you.

#include <gtk/gtk.h>

void on_btn_clicked (GtkButton *, gpointer);

int main (int argc, char *argv[])
  GtkWidget *mainw;
  GtkWidget *vbox;
  GtkWidget *btn;
  gchar     *text;

  gtk_set_locale ();
  gtk_init (&argc, &argv);

  /* a very simple window with a button
  mainw = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_widget_set_size_request (mainw, 400, -1);
  gtk_window_set_title (GTK_WINDOW (mainw), "main");
  gtk_window_set_position (GTK_WINDOW (mainw), GTK_WIN_POS_CENTER);

  vbox = gtk_vbox_new (FALSE, 0);
  gtk_widget_show (vbox);
  gtk_container_add (GTK_CONTAINER (mainw), vbox);

  btn = gtk_button_new_with_mnemonic ("Click me");
  gtk_widget_show (btn);
  gtk_box_pack_start (GTK_BOX (vbox), btn, FALSE, FALSE, 0);

  g_signal_connect ((gpointer) mainw, "destroy",
                    G_CALLBACK (gtk_main_quit),
  /* here is your text
  text = g_strdup ("your text");
  g_signal_connect ((gpointer) btn, "clicked",
                    G_CALLBACK (on_btn_clicked),

  gtk_widget_show (mainw);

  gtk_main ();

  /* not really needed, because we are quitting here
  g_free (text);

  return 0;

void on_btn_clicked (GtkButton *btn, gpointer your_data)
  g_print ("%s\n", (gchar *)your_data);
gtk-list mailing list
gtk-list gnome org

gtk-list mailing list
gtk-list gnome org

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]