Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using Qt IDE in order to build my application so as to participate to the Ubuntu Showdown contest. In my application, I've done the following:

void show_app(MainWindow *data)
    //this works fine:
    app_indicator_set_status(appindicator, APP_INDICATOR_STATUS_PASSIVE);
    //this crashes the application:

void MainWindow::make_indicator()
        //appindicator has already been created
    appindicator = app_indicator_new("Format Junkie Indicator", "formatjunkie", APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
    GtkWidget* showapp_option;
    GtkWidget* indicatormenu = gtk_menu_new();
    GtkWidget* item = gtk_menu_item_new_with_label("Format Junkie main menu");
    gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), indicatormenu);

    showapp_option = gtk_menu_item_new_with_label("Show App!");
    g_signal_connect(showapp_option, "activate", G_CALLBACK(show_app), this);
    gtk_menu_shell_append(GTK_MENU_SHELL(indicatormenu), showapp_option);

    app_indicator_set_status(appindicator, APP_INDICATOR_STATUS_ACTIVE);
    app_indicator_set_attention_icon(appindicator, "dialog-warning");

    app_indicator_set_menu(appindicator, GTK_MENU (indicatormenu));

So, basically I am trying to make a simple indicator entry, which, on click, it will hide the indicator and display the application. The indicator can be successfully hidden using the PASSIVE thingy over there, but, during the call data->show();, the application crashes.

Any help on what I am doing wrong would be appreciated! Also, please help me to correct this problem I'm facing (alternatively, I will migrate to the old and good tray icon (it works fine in 12.04, anyway) which I can handle very easily and efficiently)

share|improve this question
what is the error you are getting? – Hernantz Jul 1 '12 at 14:38
no error, it just crashes :) – hakermania Jul 1 '12 at 22:44
Can you please add the Stacktrace from the crash to you question? That will point out the exact line at which your app is crashing. If you need help with that, then check out this link… – Chris Wilson Jul 3 '12 at 17:48
Bottom line: do not mix GTK and Qt in a C++ application. The event loop is structured differently in each and you will run into nothing but trouble. – Nathan Osman Jul 3 '12 at 20:25
up vote 9 down vote accepted

You shouldn't use libappindicator for creating an Application Indicator in Qt programs. There's a better way!

If you have sni-qt installed that will automagically replace QSystemTrayIcon instances with the code for rendering that tray icon as a KDE Status Notifier Item, which the Application Indicator service will pick up and show in the Ubuntu menu bar.

share|improve this answer
Thanks. I know perfectly how the QSystemTrayIcon works, and, as I can see, sni-qt is pre-installed, so I won't be sorry if I have it as a dependency! The rules should be more clear, though, on the indicator thingy (they recommend the use of indicators, while, in fact, Qt creates tray icons which are being transformed into indicators...). You will probably have the bounty, but I have to wait 17 hours. – hakermania Jul 4 '12 at 0:25
This package(sni-qt) is now broken. – Goddard Sep 7 '13 at 5:13
"There's a better way!" Not with Qt5, there isn't. – Nathan Osman Jun 22 '14 at 23:43

I would say you try passing the "this" pointer as a pointer like "*this" here

g_signal_connect(showapp_option, "activate", G_CALLBACK(show_app), this);


g_signal_connect(showapp_option, "activate", G_CALLBACK(show_app), *this);
share|improve this answer
Thanks, by I take this as an erro (it does not compile): error: cannot convert 'MainWindow' to 'gpointer {aka void*}' for argument '4' to 'gulong g_signal_connect_data(gpointer, const gchar*, GCallback, gpointer, GClosureNotify, GConnectFlags)' – hakermania Jul 1 '12 at 22:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.