Thread: gtk callback problem in C++

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    450

    gtk callback problem in C++

    I have a callback function which I want to pass two Entrys to a read the text from the entry boxes. It appears the convention is to pass the data to the callback function as a gpointer. I am attempting to then cast this back to a struct which holds the two Entries. Here is the relevant code
    Code:
    class ChatWindow 
    {
       struct connectEntryStruct
           {
              GtkEntry *ipEntry;
    	  GtkEntry *portEntry;
           };	
       public:
        .
        .  
          void connect(GtkWidget *widget, gpointer connectEntry);
          static void staticWrapperConnect(void *ptfncHello, GtkWidget *widget, gpointer connectEntry);
    .
    .
    }
    Code:
    GtkWidget * ChatWindow::connectLayOut(GtkWidget * window)
    {
           .
           .
          .       
           GtkWidget *ipEntry = gtk_entry_new();
             
           GtkWidget *portEntry = gtk_entry_new();
       .
       .    
           connectEntryStruct * connectEntry = new connectEntryStruct;
           connectEntry->ipEntry = GTK_ENTRY(ipEntry);
           connectEntry->portEntry = GTK_ENTRY(portEntry);
        .    
           g_signal_connect (G_OBJECT (connectButton), "clicked",
                          G_CALLBACK (staticWrapperConnect), connectEntry);
     }
    Code:
       
    void ChatWindow::connect( GtkWidget *widget, gpointer connectData)
    {
        
        connectEntryStruct * connectEntry = reinterpret_cast<connectEntryStruct*>(connectData);
        const gchar * ipAdress = gtk_entry_get_text(connectEntry->ipEntry);
        const gchar * portNumber = gtk_entry_get_text(connectEntry->portEntry);
        
        g_print ("ipAdress\n");
        g_print ("portAdress\n");
    }
    
    void ChatWindow::staticWrapperConnect(void *ptfncHello, GtkWidget *widget, gpointer connectEntry)
    {
       ChatWindow *chatHello = (ChatWindow*) ptfncHello;  //cast to member function
       chatHello->connect(widget, connectEntry);
    }
    here are the errors

    (gtkwindow:13584): Gtk-CRITICAL **: file gtkentry.c: line 3871 (gtk_entry_get_text): assertion `GTK_IS_ENTRY (entry)' failed
    /bin/sh: line 1: 13584 Segmentation fault ./gtkwindow
    Press Enter to continue!

    Is it possible to do this somehow so that I can pass my Entries without making them global.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    No idea, but try http://www.spinics.net/lists/gtk/msg03864.html
    The mailing list which this site refers to looks like its worth joining (or at least reading)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  3. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  4. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 01:04 AM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM