Re: Help, how write a program to conect a server...



It is crashing because you are not handling memory
correctly. 
Firstly, look at this login function

void login(GtkWidget *widget, gpointer data)
{
gchar tmplog;

tmplog=gtk_entry_get_text(GTK_ENTRY(data));
strcpy(host.user,tmplog);
}

gtk_entry_get_text returns a gchar* not a gchar.
secondly, gtk_entry_get_text is deprecated and you
should use gtk_editable_get_chars
Also, you are passing a gpointer into a GTK_ENTRY
field? why not create a GtkWidget, and set that to a
GTK_ENTRY with a lookup_widget function and then pass
than in.

Your function should read

void login(GtkWidget *widget, gpointer data)
{
  gchar* tmplog;

  tmplog=gtk_editable_get_chars(GTK_EDITABLE(widget),
0, -1);
  strcpy(host.user,tmplog);
  g_free(tmplog);
}

All the functions need to be fixed like the above one.
Secondly, where are allocating memory for your host
structure? 
Zev.

--- javiercmx correo unam mx wrote:
Hello 

excuse me, I write a program which is connected a
server, I was seeing his code
of gftp, but I do not understand some things.

I need to know, how to get the text in GtkEntry and
GtkCombo for example the
code is:

include <gtk/gtk.h>

....

struct register
{
char *user;
char *clav;
char *srv;
} host;
...

label=gtk_label_new("User");
gtk_box_pack_start(GTK_BOX(box),label,TRUE,8,0)
gtk_widget_show(label);

login=gtk_entry_new();
gtk_widget_set_usize(login,155,-1);
gtk_signal_connect(GTK_OBJECT(login),"activate",
                   GTK_SIGNAL_FUNC(login), login)

label=gtk_label_new("Passwd");
gtk_box_pack_start(GTK_BOX(box),label,TRUE,10,0)
gtk_widget_show(label);

passwd=gtk_entry_new();
gtk_widget_set_usize(login,155,-1);
gtk_signal_connect(GTK_OBJECT(passwd),"activate",
                   GTK_SIGNAL_FUNC(passwd), passwd)

label=gtk_label_new("Server");
gtk_box_pack_start(GTK_BOX(box),label,TRUE,10,0)
gtk_widget_show(label);

server=gtk_combo_new();
gtk_widget_set_usize(170,-1);

gtk_signal_connect(GTK_OBJECT(GTK_COMBO(server)->entry,"activate",
                   GTK_SIGNAL_FUNC,server)
gtk_combo_disable_activate(GTK_COMBO(server));
gtk_box_pack_start(GTK_BOX(box),server,TRUE,10,0)

this is a widget with User:, Passwd, and server.

User and passwd use a GtkEntry
server use a GtkCombo

the functions that they are called are:

for User is

void login(GtkWidget *widget, gpointer data)
{
gchar tmplog;

tmplog=gtk_entry_get_text(GTK_ENTRY(data));
strcpy(host.user,tmplog);
}

for Passwd is

void passwd(GtkWidget *widget, gpointer data)
{
gchar tmppass;

tmppass=gtk_entry_get_text(GTK_ENTRY(data));
strcpy(host.clav,tmppass);
}

for server is

void server(GtkWidget *widget, gpointer data)
{
gchar tmpsrv;

tmpsrv=gtk_entry_get_text(GTK_ENTRY(data));
strcpy(host.srv,tmpsrv);
}

......

when press de button conect call de function
call_host

the function is 

void call_host(GtkWidget *widget, gpointer data)
{
ServerConnect();
}

In the function ServerConnect write the code that it
makes the connection to the
server. this function 

int ServerConect(void);
{
...
}

My problem is when write de user, passwd and server
in the widget and press the
button connect, appears the following message:

Illegal instruction(core dumped)
 
not where this my error or of which another form can
be done

any idea?

THANKS



-------------------------------------------------
Obtén tu correo en www.correo.unam.mx
UNAMonos Comunicándonos

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org

http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/




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