1
我必須創建一個簡單的應用程序,它在系統托盤中顯示一個圖標,並從中可以執行一些操作。 問題是創建後立即關閉了狀態圖標。少了什麼東西? 我把睡覺,以確保它被創建。在系統托盤上出現3秒鐘,即使它不是我設置的圖標。gtkmm statusicon創建後退出
Init.cc
#include <gtkmm/main.h>
#include "Tray.h"
int main(int argc, char *argv[]) {
Gtk::Main kit(argc, argv);
printf("Statuicon starting\n");
Tray tray;
printf("Statuicon started\n");
return 0;
}
Tray.cc
#include "Tray.h"
Tray::Tray() {
set(Gtk::Stock::OK);
signal_activate().connect(sigc::mem_fun(*this, &Tray::on_statusicon_activated));
signal_popup_menu().connect(sigc::mem_fun(*this, &Tray::on_statusicon_popup));
set_visible(true);
printf("Statusicon created\n");
sleep(3);
}
Tray::~Tray() {}
void Tray::on_statusicon_popup(guint button, guint activate_time) {
printf("popup!");
}
void Tray::on_statusicon_activated() {
printf("active!");
}
Tray.h
#ifndef GTKMM_TRAY_H
#define GTKMM_TRAY_H
#include <gtkmm.h>
#include <unistd.h>
using namespace std;
class Tray : public Gtk::StatusIcon {
public:
Tray();
~Tray();
private:
virtual void on_statusicon_popup(guint button, guint activate_time);
virtual void on_statusicon_activated();
};
#endif //GTKMM_TRAY_H