GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Oct 31, 2014 11:01 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Help with gtk_label_set_text
PostPosted: Fri Nov 16, 2012 3:03 am 
Offline

Joined: Thu Nov 08, 2012 12:10 am
Posts: 4
Eh, that is driving me crazy, what is the problem with code below, I am getting errors:
Quote:
forForum.c: In function ‘main’:
forForum.c:22:23: error: expected expression before ‘GtkLabel’
forForum.c:22:23: error: too few arguments to function ‘gtk_label_set_text’
/usr/include/gtk-2.0/gtk/gtklabel.h:112:23: note: declared here
forForum.c:20:9: warning: unused variable ‘str’ [-Wunused-variable]

Code:
#include <gtk/gtk.h>

int main( int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *label;

  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  gtk_window_set_title(GTK_WINDOW(window), "Set label");

  label = gtk_label_new(NULL);
   
  char *str = "Test label";
 
  gtk_label_set_text(GtkLabel(label), str);
 
  gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
  gtk_container_add(GTK_CONTAINER(window), label);
  gtk_widget_show(label);

  gtk_window_set_default_size(GTK_WINDOW(window), 300, 100);

  g_signal_connect(window, "destroy",
      G_CALLBACK (gtk_main_quit), NULL);

  gtk_widget_show(window);
  gtk_main();
  return 0;
}

Uff, I have to admit that learning GTK is a struggle. But I guess there is a steep learning curve.
Thanks in advance

Robert


Top
 Profile  
 
 Post subject: Re: Help with gtk_label_set_text
PostPosted: Fri Nov 16, 2012 4:01 am 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 177
Location: USA
The line:
gtk_label_set_text(GtkLabel(label), str);

Should be:
gtk_label_set_text(GTK_LABEL(label), str);


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group