title: How to pass a slot as an argument
body: <p>I'm using Qt 5.7 and a I have a component that behaves like a QMenuBar. This component has two methods, one, called <code>addMenu(QPushButton* menu)</code>, to add a bar menu and another, called <code>addMenuItem(QPushButton* menu, QString item, const char *slot)</code> to add the items that make up one of the bar menus. In this second method, I call addAction method of QMenu, and must pass two arguments to it: the item name and the slot that will run when the item is triggered. My question is how to do it.
  I did a search (see <a href="http://www.qtcentre.org/threads/8392-How-to-declare-SLOT-as-a-parameter-to-member-function" rel="nofollow">here</a>) and I found that QT treat slots as <code>const char *</code>, but when I try to compile my program using this method signature, it gives error, stating that there is no operator() registered for this type.</p>
  
  <p>My code:</p>
  
  <pre><code>GMInternalMenu::addMenuItem(QPushButton *menu, QString menuItem, const char* slot){
      QMenu *dropdown = mapa-&gt;value(menu);
      dropdown-&gt;addAction(menuItem, slot);
  }
  </code></pre>
  
  <p>Using the method:</p>
  
  <pre><code>ui-&gt;imMenu-&gt;addMenuItem(someButton, "Some action", SLOT(close()));
  </code></pre>
  
  <p>Output error:
  (Also on <a href="http://pastebin.com/U1LukNqX" rel="nofollow">pastebin</a>)</p>
  
  <pre><code>In file included from C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtGui/qwindowdefs.h:43:0,
                   from C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtWidgets/qwidget.h:43,
                   from C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtWidgets/qmenu.h:43,
                   from C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtWidgets/QMenu:1,
                   from ../Project/mymenu.h:4,
                   from ../Project/mymenu.cpp:1:
  C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtCore/qobject.h: In instantiation of 'static typename QtPrivate::QEnableIf&lt;(QtPrivate::FunctionPointer&lt;Func2&gt;::ArgumentCount == (-1)), QMetaObject::Connection&gt;::Type QObject::connect(const typename QtPrivate::FunctionPointer&lt;Func&gt;::Object*, Func1, const QObject*, Func2, Qt::ConnectionType) [with Func1 = void (QAction::*)(bool); Func2 = const char*; typename QtPrivate::QEnableIf&lt;(QtPrivate::FunctionPointer&lt;Func2&gt;::ArgumentCount == (-1)), QMetaObject::Connection&gt;::Type = QMetaObject::Connection; typename QtPrivate::FunctionPointer&lt;Func&gt;::Object = QAction]':
  C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtCore/qobject.h:293:74:   required from 'static typename QtPrivate::QEnableIf&lt;(QtPrivate::FunctionPointer&lt;Func2&gt;::ArgumentCount == (-1)), QMetaObject::Connection&gt;::Type QObject::connect(const typename QtPrivate::FunctionPointer&lt;Func&gt;::Object*, Func1, Func2) [with Func1 = void (QAction::*)(bool); Func2 = const char*; typename QtPrivate::QEnableIf&lt;(QtPrivate::FunctionPointer&lt;Func2&gt;::ArgumentCount == (-1)), QMetaObject::Connection&gt;::Type = QMetaObject::Connection; typename QtPrivate::FunctionPointer&lt;Func&gt;::Object = QAction]'
  C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtWidgets/qmenu.h:120:9:   required from 'QAction* QMenu::addAction(const QString&amp;, Func1, const QKeySequence&amp;) [with Func1 = const char*]'
  ../Project/mymenu.cpp:35:39:   required from here
  C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtCore/qglobal.h:746:47: error: static assertion failed: Signal and slot arguments are not compatible.
   #define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
                                                 ^
  C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtCore/qobject.h:306:9: note: in expansion of macro 'Q_STATIC_ASSERT_X'
           Q_STATIC_ASSERT_X((FunctorArgumentCount &gt;= 0),
           ^
  In file included from C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtCore/qobjectdefs.h:50:0,
                   from C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtGui/qwindowdefs.h:44,
                   from C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtWidgets/qwidget.h:43,
                   from C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtWidgets/qmenu.h:43,
                   from C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtWidgets/QMenu:1,
                   from ../Project/mymenu.h:4,
                   from ../Project/mymenu.cpp:1:
  C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtCore/qobjectdefs_impl.h: In instantiation of 'struct QtPrivate::FunctorReturnType&lt;const char*, QtPrivate::List&lt;&gt; &gt;':
  C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtCore/qobject.h:309:158:   required from 'static typename QtPrivate::QEnableIf&lt;(QtPrivate::FunctionPointer&lt;Func2&gt;::ArgumentCount == (-1)), QMetaObject::Connection&gt;::Type QObject::connect(const typename QtPrivate::FunctionPointer&lt;Func&gt;::Object*, Func1, const QObject*, Func2, Qt::ConnectionType) [with Func1 = void (QAction::*)(bool); Func2 = const char*; typename QtPrivate::QEnableIf&lt;(QtPrivate::FunctionPointer&lt;Func2&gt;::ArgumentCount == (-1)), QMetaObject::Connection&gt;::Type = QMetaObject::Connection; typename QtPrivate::FunctionPointer&lt;Func&gt;::Object = QAction]'
  C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtCore/qobject.h:293:74:   required from 'static typename QtPrivate::QEnableIf&lt;(QtPrivate::FunctionPointer&lt;Func2&gt;::ArgumentCount == (-1)), QMetaObject::Connection&gt;::Type QObject::connect(const typename QtPrivate::FunctionPointer&lt;Func&gt;::Object*, Func1, Func2) [with Func1 = void (QAction::*)(bool); Func2 = const char*; typename QtPrivate::QEnableIf&lt;(QtPrivate::FunctionPointer&lt;Func2&gt;::ArgumentCount == (-1)), QMetaObject::Connection&gt;::Type = QMetaObject::Connection; typename QtPrivate::FunctionPointer&lt;Func&gt;::Object = QAction]'
  C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtWidgets/qmenu.h:120:9:   required from 'QAction* QMenu::addAction(const QString&amp;, Func1, const QKeySequence&amp;) [with Func1 = const char*]'
  ../Project/mymenu.cpp:35:39:   required from here
  C:/Qt/Qt5.7.0/5.7/mingw53_32/include/QtCore/qobjectdefs_impl.h:632:78: error: request for member 'operator()' in 'QtPrivate::FunctorReturnType&lt;Functor, QtPrivate::List&lt;Tail ...&gt; &gt;::dummy&lt;const char*&gt;()', which is of non-class type 'const char*'
           typedef decltype(dummy&lt;Functor&gt;().operator()((dummy&lt;ArgList&gt;())...)) Value;
  </code></pre>