C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 12-31-2004, 05:59 PM   #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.
curlious is offline   Reply With Quote
Old 01-01-2005, 01:31 AM   #2
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,676
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)
Salem is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
WS_POPUP, continuation of old problem blurrymadness Windows Programming 1 04-20-2007 06:54 PM
Laptop Problem Boomba Tech Board 1 03-07-2006 06:24 PM
Sorting problem.. well actually more of a string problem fatdunky C Programming 5 11-07-2005 11:34 PM
searching problem DaMenge C Programming 9 09-12-2005 01:04 AM
half ADT (nested struct) problem... CyC|OpS C Programming 1 10-26-2002 08:37 AM


All times are GMT -6. The time now is 03:08 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22