问题描述
我必须创建一个简单的应用程序,在系统托盘中显示一个图标,并从中进行一些操作。
问题是statusicon在创建后立即关闭。少了什么东西?
我把睡眠确保它是创建的。
Init.cc
pre> #include< gtkmm / main.h>
#includeTray.h
int main(int argc,char * argv []){
Gtk :: Main kit(argc,argv)
printf(Statuicon starting \\\
);
托盘;
printf(Statuicon started \\\
);
return 0;
}
Tray.cc
#includeTray.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\\\
);
sleep(3);
}
Tray ::〜Tray(){}
void Tray :: on_statusicon_popup(guint button,guint activate_time){
printf弹出!);
}
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
根本没有运行主循环,因此没有输入事件可以处理,程序在构建托盘后退出。你想做的是删除睡眠,然后在你的main()函数中,在返回之前添加以下行:
Gtk :: Main :: run();
然后,当您希望应用程序退出(通常是响应某种事件)调用
Gtk :: Main :: quit();
I have to create a simple application that displays an icon in the systray and a menu from which you can do some operations.the problem is that statusicon is closed immediately after creation. What's missing?I put the sleep to make sure it was created. for 3 seconds something appears in systray, even if it is not the icon that I set.
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
You're not running a main loop at all, so no input events can be handled and the program exits after constructing the tray. What you want to do is delete the sleep, and then in your main() function, add the following line right before the return:
Gtk::Main::run();
Then, when you want the application to quit (generally in response to an event of some sort), call
Gtk::Main::quit();
这篇关于gtkmm statusicon在创建后退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!