简体   繁体   English

GTK应用程序:如何使用Qt / C ++创建工作指标?

[英]GTK app: How do I create a working indicator with Qt/C++?

I've tried in 2 forums, but I had no luck so far. 我已经在2个论坛中尝试过,但是到目前为止我还没有运气。

So, I am using Qt IDE in order to build my application so as to participate to the Ubuntu Showdown contest. 因此,我正在使用Qt IDE来构建我的应用程序,以便参加Ubuntu Showdown竞赛。 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:
    data->show();
}


void MainWindow::make_indicator()
{
    if(appindicator){
        //appindicator has already been created
        return;
    }
    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);

    gtk_widget_show_all(indicatormenu);
    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. 使用该处的PASSIVE工具可以成功隐藏该指示器,但是在调用data-> show();期间,应用程序崩溃。

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 Ubuntu 12.04, anyway) which I can handle very easily and efficiently) 另外,请帮助我纠正我面临的这个问题(或者,我将迁移到旧的且良好的任务栏图标(无论如何,它在Ubuntu 12.04中都可以正常工作),我可以非常轻松有效地处理它)

The callback for the activate signal needs to have the following type: activate信号的回调必须具有以下类型:

void callback(GtkMenuItem *, gpointer)

So show_app should be defined like this 所以show_app应该这样定义

void show_app(GtkMenuItem *showapp_option, MainWindow *data)

That should solve your problem. 那应该解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM