如何使用Qt / C ++创建工作指示器?

我正在使用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 thingy成功隐藏指示符,但是,在调用data-> show();期间,应用程序崩溃。

任何有关我做错的任何帮助将不胜感激! 另外,请帮助我纠正我面临的这个问题(或者,我将迁移到旧的和好的托盘图标(它在12.04工作正常),我可以非常容易和有效地处理)

您不应该使用libappindicator在Qt程序中创建应用程序指示器。 还有更好的方法!

如果您安装了sni-qt ,它将自动将QSystemTrayIcon实例替换为将该托盘图标呈现为KDE状态通知程序项的代码 , 应用程序指示器服务将在Ubuntu菜单栏中提取并显示该项目。

我会说你尝试将“this”指针作为指针传递给“* this”这里

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

 g_signal_connect(showapp_option, "activate", G_CALLBACK(show_app), *this); 
Interesting Posts