views:

54

answers:

1

hello, 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(bf2142);
TrayIcon.setContextMenu(&menu);
return oApp.exec();

}

but how can i make that when i open the menu and press on action1 that it execute a function?

thnx very much!

+2  A: 

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()));
atomice