Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 511903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:15:54+00:00 2026-05-13T07:15:54+00:00

I would like to have a statusbar, so I started by making a small

  • 0

I would like to have a statusbar, so I started by making a small program with just a statusbar, so I could see how it worked.

Right now I would just like to be able to get some text in it, but it shows a random character instead.

Can someone see what’s wrong with my code?

#include <gtk/gtk.h>

int main (int argc, char *argv[]) {
  GtkWidget *window, *statusbar, *vbox;
  gchar *info;
  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_widget_set_size_request(window, 250, -1);

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

  statusbar = gtk_statusbar_new();

  /* stack for info messages */
  g_object_set_data(G_OBJECT(statusbar), "info", (gpointer) "1");
  g_object_set_data(G_OBJECT(statusbar), "info", (gpointer) "2");
  g_object_set_data(G_OBJECT(statusbar), "info", (gpointer) "3");

  /* stack for warning messages */
  g_object_set_data(G_OBJECT(statusbar), "warning", (gpointer) "A");
  g_object_set_data(G_OBJECT(statusbar), "warning", (gpointer) "B");
  g_object_set_data(G_OBJECT(statusbar), "warning", (gpointer) "C");

  /* get id for the message at the top of the info stack? */
  guint id = gtk_statusbar_get_context_id(statusbar, "info");
  /* show the top message from the info stack ? */
  gtk_statusbar_push(statusbar, id, info);

  vbox = gtk_vbox_new(FALSE, 5);  
  gtk_box_pack_start_defaults(GTK_BOX (vbox), statusbar);
  gtk_container_add(GTK_CONTAINER(window), vbox);

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

I get these warnings

s.c:26: warning: passing argument 1 of ‘gtk_statusbar_get_context_id’ from incompatible pointer type
/usr/include/gtk-2.0/gtk/gtkstatusbar.h:94: note: expected ‘struct GtkStatusbar *’ but argument is of type ‘struct GtkWidget *’
s.c:28: warning: passing argument 1 of ‘gtk_statusbar_pop’ from incompatible pointer type
/usr/include/gtk-2.0/gtk/gtkstatusbar.h:100: note: expected ‘struct GtkStatusbar *’ but argument is of type ‘struct GtkWidget *’
s.c:28: error: too many arguments to function ‘gtk_statusbar_pop’
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:15:54+00:00Added an answer on May 13, 2026 at 7:15 am

    You declared GtkWidget *statusbar but the gtk_statusbar_... methods expect GtkStatusbar *: casting it with GTK_STATUSBAR(statusbar) removes the warnings. This is not a big issue as the program would work anyway: the biggest problem is you’re using info without initializing it.

    The following code is working as expected here:

    /* gcc -o status status.c $(pkg-config --cflags --libs gtk+-2.0) */
    
    #include <gtk/gtk.h>
    
    int main (int argc, char *argv[]) {
        GtkWidget *window, *statusbar, *vbox;
        gchar *info;
        gtk_init(&argc, &argv);
    
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_widget_set_size_request(window, 250, -1);
    
        g_signal_connect(G_OBJECT(window), "destroy",
                         G_CALLBACK(gtk_main_quit), NULL);
    
        statusbar = gtk_statusbar_new();
    
        /* stack for info messages */
        g_object_set_data(G_OBJECT(statusbar), "info", (gpointer)
                          "1");
        g_object_set_data(G_OBJECT(statusbar), "info",
                          (gpointer) "2");
        g_object_set_data(G_OBJECT(statusbar), "info",
                          (gpointer) "3");
    
        /* stack for warning messages */
        g_object_set_data(G_OBJECT(statusbar), "warning",
                          (gpointer) "A");
        g_object_set_data(G_OBJECT(statusbar), "warning",
                          (gpointer) "B");
        g_object_set_data(G_OBJECT(statusbar),
                          "warning", (gpointer) "C");
    
        /* get id for the message at the top of the
         * info stack? */
        guint id = gtk_statusbar_get_context_id(GTK_STATUSBAR(statusbar), "info");
        /* show the top message from the info stack
         * ? */
        info = "This was uninitialized";
        gtk_statusbar_push(GTK_STATUSBAR(statusbar), id, info);
    
        vbox = gtk_vbox_new(FALSE, 5);
        gtk_box_pack_start_defaults(GTK_BOX
                                    (vbox),
                                    statusbar);
        gtk_container_add(GTK_CONTAINER(window),
                          vbox);
    
        gtk_widget_show_all(window);
        gtk_main();
        return 0;
    }
    

    I don’t know what are you trying to achieve with g_object_set_data though, but maybe they are only old tests…

    Addendum:

    You should use gtk_statusbar_push() to pile up messages on the status bar stack. With gtk_statusbar_pop() you’ll remove the last pushed message, discovering the previous one.

    gtk_statusbar_push(GTK_STATUSBAR(statusbar), id, "First message");
    // Now the statusbar shows "First message"
    gtk_statusbar_push(GTK_STATUSBAR(statusbar), id, "Second message");
    // Now the statusbar shows "Second message"
    gtk_statusbar_pop(GTK_STATUSBAR(statusbar), id);
    // Now the statusbar shows "First message"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We would like to have user defined formulas in our c++ program. e.g. The
I have a problem that I would like have solved via a SQL query.
I would like to have a reference for the pros and cons of using
I would like to have an iframe take as much vertical space as it
I would like to have a VM to look at how applications appear and
I would like to have a nice template for doing this in development. How
I would like to have all developers on my team to use the same
I would like to have information about the icons which are displayed alongside the
I would like to have the same editor available on all of the platforms
I would like to have a Java component which has a resize icon on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.