[讨论]GTK编程问题 get_entry_get_text取值

开发基于GTK+或QT的应用程序
回复
reelcol
帖子: 1
注册时间: 2007-09-13 14:09
送出感谢: 0
接收感谢: 0

[讨论]GTK编程问题 get_entry_get_text取值

#1

帖子 reelcol » 2007-09-13 14:11

程序大概是这样

代码: 全选

userlogin.h
class UserLoginWin {
private:
    GtkWidget *user_entry;
    GtkWidget *passwd_entry;
    static void on_Login_button_clicked(GtkWidget *widget, UserLoginWin *oUserLoginWin);
    
public:
    UserLoginWin();
    void Login(GtkWidget *hbox, GtkWidget *frame);
};


userloginwin.cpp:

void UserLoginWin::Login(GtkWidget *hbox, GtkWidget *frame)
{
    ....
    GtkWidget *table = gtk_table_new(2, 2, FALSE);
    gtk_box_pack_start(GTK_BOX(vbox), table, false, false, 0);
    gtk_container_set_border_width(GTK_CONTAINER(table), 12);
    label = gtk_label_new_with_mnemonic(_("_User Name:"));
    user_entry = gtk_entry_new ();
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), user_entry);
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_FILL, (GtkAttachOptions)0, 6, 4);
    gtk_table_attach(GTK_TABLE(table), user_entry, 1, 2, 0, 1, GTK_EXPAND, (GtkAttachOptions)0, 0, 4);
    label = gtk_label_new_with_mnemonic(_("_Password:"));
    passwd_entry = gtk_entry_new ();
    gtk_entry_set_visibility(GTK_ENTRY(passwd_entry), FALSE);
    gtk_label_set_mnemonic_widget (GTK_LABEL (label), passwd_entry);
    gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, GTK_FILL, (GtkAttachOptions)0, 6, 4);
    gtk_table_attach(GTK_TABLE(table), passwd_entry, 1, 2, 1, 2, GTK_EXPAND, (GtkAttachOptions)0, 0, 4);
    .....
    GtkWidget *LoginButton = gtk_button_new();
    gtk_container_add (GTK_CONTAINER(LoginButton), hbox3);
    label = gtk_label_new_with_mnemonic(_("_Login"));
    gtk_box_pack_start(GTK_BOX (hbox3), label, FALSE, FALSE, 0);
    gtk_label_set_mnemonic_widget(GTK_LABEL(label), LoginButton);
    g_signal_connect(G_OBJECT(LoginButton),"clicked", G_CALLBACK(on_Login_button_clicked), this);
    gtk_box_pack_end(GTK_BOX(hbox2), LoginButton, false, false, 0);
    ......

}

void UserLoginWin::on_Login_button_clicked(GtkWidget *widget, UserLoginWin *oUserLoginWin)
{
    const char *euser = gtk_entry_get_text(GTK_ENTRY(oUserLoginWin- >user_entry));
    printf("ddddddd %s\n", euser);

    const gchar *epassword = gtk_entry_get_text(GTK_ENTRY(oUserLoginWin- >passwd_entry));
    printf("ccccccc %s\n", epassword);
    
}
编译后打印结果
dddddddd
cccccccc

就是说gtk_entry_get_text 取不到值, 请教好心人给帮忙看看。
Robinho
帖子: 22
注册时间: 2007-03-01 15:22
来自: 广州
送出感谢: 0
接收感谢: 0

#2

帖子 Robinho » 2007-09-13 20:50

汗。。多了个o
oUserLoginWin
回复

回到 “GTK+和QT”