c++ - GTK 应用程序 : How do I create a working indicator with Qt/C++?

标签 c++ c qt gtk indicator

我已经在 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 中工作正常)我可以非常容易和有效地处理)

最佳答案

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

void callback(GtkMenuItem *, gpointer)

所以show_app应该这样定义

void show_app(GtkMenuItem *showapp_option, MainWindow *data)

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

关于c++ - GTK 应用程序 : How do I create a working indicator with Qt/C++?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11315574/

相关文章:

c++ - Qt Widget 在初始化时被调整了两次?

Qt绘画不清除背景

C - 在 char * 循环上出现段错误

c++ - 如何在 XWindows 中获取装饰窗口的内部尺寸?

c++ - Valgrind 合法的 "possibly lost"字节示例

c++ - 编译 ssl 客户端的 boost 示例时出错

linux - Qt:为什么我的自定义 qgraphicsview 小部件在 Linux 上编译期间会产生错误?

c++ - 关于模板结构大小的静态断言

c++ - 使用 Boost.Spirit 在 C++ 中解析 SQL 查询

c++ - Visual C++ 2010 Express x64 程序集