but so as to use the syntax of the function pointer as in QObject :: connect in the QT5 version, and not (const char *):

connect(const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type) 

For example, I want to create a class function like this:

 class CommandHub : public QObject { Q_OBJECT public: ... //эта void connectCommand(const QString &commandId, QObject *object, PointerToMemberFunction slot); ... }; 

I want to call connectCommand as follows:

 CommandHub commandHub; //... commandHub.connectCommand("open", someWidget, &SomeWidget::onOpen); 

That is, the question is: what to use instead of PointerToMemberFunction, so that you can substitute a pointer to the slot of the object?

  • Make an example of what you want to achieve, but nothing is clear. - ixSci pm
  • added what I want to achieve, that is, call connectCommand - asianirish

2 answers 2

You can write your function like this:

 template <typename Sender, typename SlotType> void connectCommand(const QString &commandId, Sender* object, SlotType slot); 

    Everything is simple - we take the editor and see, and how this connect declared for this case

      static QMetaObject::Connection connect(const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type = Qt::AutoConnection); 

    That is, the slot type has the form const QMetaMethod & .

    • I do not know exactly what the author is asking, but this answer is definitely not to his question. He has a new syntax question, and you have the answer with the old one. - ixSci
    • With the old char there. - KoVadim
    • There are both in the old version. - ixSci