c++ - QT SLOT: Pointer to Member Function error -


i'm working on qt project , have troubles slots. want pass pointer member function argument of slot. this, declared slot in class when so, moc error. don't know if want achieve possible.

an exemple of syntax class named mainframe:

void slotanswerreceived (qstring answer, void (mainframe::*ptr)(qstring)); 

i don't have connect anywhere, nothing using function, , error have on line above.

thank help. cannot find solution on web (but found article explaining signal , slot in depth if interested).

  1. declare typedef pointer-to-member type.

  2. declare , register metatype typedef.

  3. only use typedef - remember moc uses string comparison determine type equality, has no c++ type expression parser.

an example follows. @ time a.exec() called, there 2 qmetacallevent events in event queue. first 1 c.callslot, second 1 a.quit. executed in order. recall queued call (whether due invokemethod or due signal activation) results in posting of qmetacallevent each receiver.

#include <qcoreapplication> #include <qdebug> #include <qmetaobject>  class class : public qobject {    q_object public:    typedef void (class::*method)(const qstring &); private:    void method(const qstring & text) { qdebug() << text; }    q_slot void callslot(const qstring & text, class::method method) {       (this->*method)(text);    }    q_signal void callsignal(const qstring & text, class::method method); public:    class() {       connect(this, signal(callsignal(qstring,class::method)),               slot(callslot(qstring,class::method)),               qt::queuedconnection);       emit callsignal("hello", &class::method);    } }; q_declare_metatype(class::method)  int main(int argc, char *argv[]) {    qregistermetatype<class::method>();    qcoreapplication a(argc, argv);    class c;    qmetaobject::invokemethod(&a, "quit", qt::queuedconnection);    return a.exec(); }  #include "main.moc" 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -