我在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它执行某个功能时,我怎么能这样做呢?
非常感谢!答案 0 :(得分:3)
创建一个新类(从QObject派生),其中包含一个名为的插槽,例如myslot,然后:
class MyClass : public QObject {
Q_OBJECT
...
public slots:
void mySlot();
};
myObject = new MyClass();
connect(action1, SIGNAL(triggered()), myObject, SLOT(mySlot()));