【问题标题】:GTK app: How do I create a working indicator with Qt/C++?GTK 应用程序:如何使用 Qt/C++ 创建工作指标?
【发布时间】:2012-07-03 16:53:09
【问题描述】:

我已经在 2 个论坛中尝试过,但到目前为止我都没有运气。

所以,我正在使用 Qt IDE 来构建我的应用程序,以便参加 Ubuntu Showdown 比赛。在我的应用程序中,我做了以下事情:

    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));
}

所以,基本上我正在尝试制作一个简单的指示器条目,单击它会隐藏指示器并显示应用程序。可以使用那边的 PASSIVE 东西成功隐藏指示器,但是在调用 data->show(); 期间,应用程序崩溃了。

对我做错的任何帮助将不胜感激!另外,请帮助我纠正我面临的这个问题(或者,我将迁移到旧的和好的托盘图标(它在 Ubuntu 12.04 中运行良好,无论如何),我可以非常轻松有效地处理)

【问题讨论】:

  • 你能详细说明你是如何做到这一点的吗?
  • @Goddard 下载源代码bit.ly/1dQggw1 并在 nongui.cpp 搜索指标

标签: c++ c qt gtk indicator


【解决方案1】:

activate 信号的回调需要具有以下类型:

void callback(GtkMenuItem *, gpointer)

所以show_app应该这样定义

void show_app(GtkMenuItem *showapp_option, MainWindow *data)

这应该可以解决您的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多