Nathan Osman
Nathan Osman

Reputation: 73285

Why is GTK spewing a ton of (seemingly) irrelevant warnings?

Here is a very simple GTK application that creates an application indicator:

#include <gtk/gtk.h>
#include <libappindicator/app-indicator.h>

int main()
{
    AppIndicator *indicator;
    GtkWidget *menu;
    GtkWidget *item1;
    GtkWidget *item2;
    GtkWidget *separator;

    indicator = app_indicator_new("testapp", "distributor-logo", APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
    menu = gtk_menu_new();

    app_indicator_set_menu(indicator, GTK_MENU(menu));
    app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE);

    item1 = gtk_menu_item_new_with_label("Item 1");
    item2 = gtk_menu_item_new_with_label("Item 2");
    separator = gtk_separator_menu_item_new();

    gtk_widget_show(item1);
    gtk_widget_show(item2);
    gtk_widget_show(separator);

    gtk_menu_shell_append(GTK_MENU_SHELL(menu), item1);
    gtk_menu_shell_append(GTK_MENU_SHELL(menu), separator);
    gtk_menu_shell_append(GTK_MENU_SHELL(menu), item2);

    gtk_main();

    return 0;
}

I compiled the application with the following command:

gcc `pkg-config --cflags appindicator-0.1` -o testapp testapp.c \
    `pkg-config --libs appindicator-0.1`

The application runs and displays the indicator as expected. However, it spews a ton of warnings that don't seem to have anything to do with my application. You can view the full list here, but here are the first few:

(process:17410): Gtk-CRITICAL **: IA__gtk_icon_theme_get_for_screen: assertion 'GDK_IS_SCREEN (screen)' failed

(process:17410): GLib-GObject-WARNING **: invalid (NULL) pointer instance

(process:17410): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed

(process:17410): GLib-GObject-WARNING **: invalid (NULL) pointer instance

What do these warnings mean and how do I fix my application to prevent them from being raised in the first place?

Upvotes: 2

Views: 100

Answers (1)

Nathan Osman
Nathan Osman

Reputation: 73285

I was able to make all of the warnings disappear by adding the following line to the beginning:

gtk_init(&argc, &argv);

I also modified the signature of main() to main(int argc, char **argv).

Upvotes: 2

Related Questions