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); }here are the errorsCode: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); }
(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.



LinkBack URL
About LinkBacks


