- explicit Action(QObject *parent);
- Action(const QString &text, QObject *parent, const QObject *receiver = 0, const char *slot = 0, const QKeySequence &shortcut = 0);
- Action(const QIcon &icon, const QString &text, QObject *parent, const QObject *receiver = 0, const char *slot = 0, const QKeySequence &shortcut = 0);
+ explicit Action(QObject* parent);
+ Action(const QString& text, QObject* parent, const QKeySequence& shortcut = 0);
+ Action(const QIcon& icon, const QString& text, QObject* parent, const QKeySequence& shortcut = 0);
+
+ template<typename Receiver, typename Slot>
+ Action(const QString& text, QObject* parent, const Receiver* receiver, Slot slot, const QKeySequence& shortcut = 0)
+ : Action(text, parent, shortcut)
+ {
+ static_assert(!std::is_same<Slot, const char*>::value, "Old-style connects not supported");
+
+ setShortcut(shortcut);
+ connect(this, &QAction::triggered, receiver, slot);
+ }
+
+ template<typename Receiver, typename Slot>
+ Action(const QIcon& icon, const QString& text, QObject* parent, const Receiver* receiver, Slot slot, const QKeySequence& shortcut = 0)
+ : Action(text, parent, receiver, slot, shortcut)
+ {
+ setIcon(icon);
+ }