开发者

Adding slots to automatically created menu items

I have an existing menu called save and in it i want to add two menus,Save New and Save Edits.

QMenu *menu = new QMenu(this);
menu->addAction("Save New");//void saveNew()
menu->addAction("Save Edits");/开发者_如何学JAVA/void saveEdits()
ui.saveButton->setMenu(menu);

I have looked up for a suitable function and found this but i need help implemening it.

QAction * QMenu::addAction ( const QString & text, const QObject * receiver, const char * member, const QKeySequence & shortcut = 0 )

How can i do it?.


menu->addAction("Save New", this, SLOT(saveNew()));

With the same parameters you would use in that connect call:

QAction *saveAction = menu->addAction("Save New");
connect(saveAction, SIGNAL(triggered()), this, SLOT(saveNew()));

If the menu was created in the designer, you can connect the corresponding actions that were created at the same time:

connect(ui.saveAction, SIGNAL(triggered()), this, SLOT(saveNew()));

or use the signal/slot editor to connect directly the actions from within the designer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜