I've a button with menus like so:
action1 = menu->addAction(tr("Topography"));
action2 = menu->addAction(tr("Landsat"));
pButton2->setMenu(menu);
connect(action1, SIGNAL(triggered()), this, SLOT(mySlot(1))); //wrong
connect(action2, SIGNAL(triggered()), this, SLOT(mySlot(2)));
pButton2 = new QPushButton(tr("&Terrain"));
menu = new QMenu(this);
action1 = menu->addAction(tr("Topography"));
action2 = menu->addAction(tr("Landsat"));
pButton2->setMenu(menu);
connect(action1, SIGNAL(triggered()), this, SLOT(mySlot(1))); //wrong
connect(action2, SIGNAL(triggered()), this, SLOT(mySlot(2)));
To copy to clipboard, switch view to plain text mode
I know why this doesn't work: triggered() has no parameters, mySlot(int) has one. I could fix this by making 2 separate mySlot() functions that don't take parameters, but I'm going to have alot of these and was wondering if there's another, better way to do it... a way such that I can create a single SLOT function.
Bookmarks