Re: easy gtk-programm fault
- From: Axel Simon <A Simon kent ac uk>
 
- To: Daniel Dieterle <daniel dieterle ws>
 
- Cc: gtk-app-devel-list gnome org
 
- Subject: Re: easy gtk-programm fault
 
- Date: Tue, 17 Jan 2006 14:35:13 +0000
 
On Tue, 2006-01-17 at 15:29 +0100, Daniel Dieterle wrote:
hallo everybody,
since some days i try to code my first gtk program. it 's not more than 
a window with a label in it.
the code is that:
#include <gtk/gtk.h>
int main( int argc,
                char *argv[] )
{
        GtkWidget *window1;
        GtkWidget *label1;
        
        gtk_init (&argc, &argv);
        window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        label1 = gtk_label_new ("Hallo Du");
        gtk_container_add (GTK_CONTAINER (window1), label1);
        
        gtk_widget_show (label1);
        gtk_widget_show (window1);      
//     sleep(1);
//      gtk_label_set_text (label1,"wie gehts?");
        
        gtk_main ();
        return 0;
}
there is no thing to warry about.
but my aim is to change the text in the label. and if i uncomment the 
"gkt_label_set_text ..."-line, gcc (gcc label.c `pkg-config --cflags 
--libs gtk+-2.0`) shows a warning:
label.c: In Funktion ÂmainÂ:
label.c:22: Warnung: Verarbeiten des Argumentes 1 von Âgtk_label_set_text von inkompatiblem Zeigertyp
which means that the "label1" in the "set_text"-line is a incompatible 
pointertype, i think.
do anybody know, what i'm doing wrong?
You should declare the label1 variable as GtkLabel*. The compiler
complains because you use a more general GtkWidget pointer as GtkLabel
pointer.
Besides, the program will not display the original text, since the main
loop must be run to display anything. Consider defining a call back that
sets the label. Then you can tell Gtk to call that call back after 1s
using g_timeout_add:
http://developer.gnome.org/doc/API/2.0/glib/glib-The-Main-Event-
Loop.html#g-timeout-add
Axel.
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]