[Solved] QMenu::addAction with auto connection not working.
-
There are two overloads of addAction that are supposed to automatically connect the new action to a slot. Check "here":http://qt-project.org/doc/qt-5/qmenu.html for actual signature.
The connection is either not created or does not work. If I use the normal non-connecting overload and connect it manually, it works fine.
Here is my code that calls one of these function:
@
contactsMenu->addAction(mStatusIcons.at(STATUS_ONLINE), QString("Hide Contacts"), this, "showContacts", QKeySequence(Qt::Key_S));
@I have also tried adding () to showContacts (making "showContacts()) which doesn't work either. Is their something else I am missing?
Here is the function it is supposed to call (truncated for brevity):
@
void SocialMode::showContacts()
{
mP->contactsVisible = ~mP->contactsVisible;if (mP->contactsVisible)
{
mP->showContactList->setIcon(mStatusIcons.at(STATUS_ONLINE));
mP->showContactList->setText("Hide Contact List");
// show the contact list...
}
else
{
mP->showContactList->setIcon(mStatusIcons.at(STATUS_OFFLINE));
mP->showContactList->setText("Show Contact List");
// hide the contact list...
}
}
@ -
You should use the SLOT macro for the member parameter of addAction(), just like in a plain connect(). A string name of the slot won't work.
That's actually true for all places where a signal/slot name is required via const char* parameter, exception being the QMetaObject and friends. -
Thanks for that. It worked.