Help how to properly connect Q_OBJECT to work signals and slots. example: mycall.h

#ifndef MYCALL_H #define MYCALL_H #include <pjsua2.hpp> #include <iostream> #include <memory> #include <pj/file_access.h> #include <QDebug> #include "myaccount.h" #define THIS_FILE "main.cpp" using namespace pj; class MyAccount; class MyCall : public Call { private: MyAccount *myAcc; public: MyCall(Account &acc, int call_id = PJSUA_INVALID_ID); virtual void onCallState(OnCallStateParam &prm); virtual void onCallMediaState(OnCallMediaStateParam &prm); }; #endif // MYCALL_H 

mycall.cpp

 #include "mycall.h" MyCall::MyCall(Account &acc, int call_id) : Call(acc, call_id) { myAcc = (MyAccount *)&acc; } void MyCall::onCallState(OnCallStateParam &prm) { PJ_UNUSED_ARG(prm); CallInfo ci = getInfo(); //std::cout << "*** Call: " << ci.remoteUri << " [" << ci.stateText << "]" << std::endl; if (ci.state == PJSIP_INV_STATE_DISCONNECTED) { myAcc->removeCall(this); /* Delete the call */ delete this; } } void MyCall::onCallMediaState(OnCallMediaStateParam &prm) { CallInfo ci = getInfo(); // Iterate all the call medias for (unsigned i = 0; i < ci.media.size(); i++) { if (ci.media[i].type==PJMEDIA_TYPE_AUDIO && getMedia(i)) { AudioMedia *aud_med = (AudioMedia *)getMedia(i); // Connect the call audio media to sound device AudDevManager& mgr = Endpoint::instance().audDevManager(); aud_med->startTransmit(mgr.getPlaybackDevMedia()); mgr.getCaptureDevMedia().startTransmit(*aud_med); } } } 

just adding a macro to a class doesn't help

  • Your class should start like this class MyCall : public QObject, public Call { Q_OBJECT - KoVadim

1 answer 1

In order for signals and slots to work, your class must be a QObject descendant and have the Q_OBJECT macro in a private domain Q_OBJECT

  • did so class MyCall: public QObject, public Call {Q_OBJECT now swears on the implementation. although I also set qobject to ndefined reference to `vtable for MyCall 'implementation: MyCall :: MyCall (Account & acc, int call_id): QObject (), Call (acc, call_id) - Alexey Smirnov
  • @Alexey_Smirnov Build-> Run qmake. Then rebuild the project. Should help. - zaurilla
  • Yes. Thank you) Moving off the ground;) - Alexey Smirnov