Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] QMenu::addAction with auto connection not working.

[Solved] QMenu::addAction with auto connection not working.

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    primem0ver
    wrote on last edited by
    #1

    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...
    }
    }
    @

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        primem0ver
        wrote on last edited by
        #3

        Thanks for that. It worked.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved