本文介绍了C ++ Qt任务栏图标菜单操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在qt创作者中获得了这段代码;
I got this code in qt creator;
int main( int argc, char* argv[] )
{
QApplication oApp( argc, argv );
QAction *action1;
QMenu menu;
QSystemTrayIcon TrayIcon( QIcon("favicon.ico") );
TrayIcon.show();
action1= new QAction("action1", NULL);
action1->setStatusTip("Create a new file");
menu.addAction(action1);
TrayIcon.setContextMenu(&menu);
return oApp.exec();
}
但是当我打开菜单并在action1上按它执行功能时,我该怎么做呢?
but how can i make that when i open the menu and press on action1 that it execute a function?
非常感谢!
推荐答案
创建一个新类(从QObject派生),其插槽名为myslot,然后:
Create new class (derived from QObject) with a slot called, e.g. myslot, then:
class MyClass : public QObject {
Q_OBJECT
...
public slots:
void mySlot();
};
myObject = new MyClass();
connect(action1, SIGNAL(triggered()), myObject, SLOT(mySlot()));
这篇关于C ++ Qt任务栏图标菜单操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!