QT中我自定义了一个类并继承了IRtcEngineEventHandler这个类,但是加入房间的时候没有调用我重写的回调函数

class EventHandler : public IRtcEngineEventHandler
{
public:
explicit EventHandler();
virtual ~EventHandler() override;
void setMainWnd(HWND hWnd = nullptr);
HWND GetMsgReceiver() {return m_hMainWnd;}

virtual void onJoinChannelSuccess(const char* channel, uid_t uid, int elapsed) override;//加入频道回调
virtual void onRejoinChannelSuccess(const char* channel, uid_t uid, int elapsed) override;//重新加入频道回调

private:
HWND m_hMainWnd;
};

你看看这篇教程:Agora 教程 | 如何使用 Qt 开发音视频通话应用

没走 onJoinChannelSuccess 回调吗?那也有可能是加入频道失败了啊。

// 这里我们将事件从 AgoraRtcEngine 的信号函数发出,并在 UI 中进行响应,不做复杂的处理逻辑。
class AgoraRtcEngineEvent : public agora::rtc::IRtcEngineEventHandler {
 public:
  AgoraRtcEngineEvent(AgoraRtcEngine &engine)
    :m_engine(engine) {}
​
  virtual void onVideoStopped() override {
    emit m_engine.videoStopped();
  }
​
  virtual void onJoinChannelSuccess(const char *channel, uid_t uid,
                                    int elapsed) override {
    emit m_engine.joinedChannelSuccess(channel, uid, elapsed);
  }
​
  virtual void onUserJoined(uid_t uid, int elapsed) override {
    emit m_engine.userJoined(uid, elapsed);
  }
​
  virtual void onUserOffline(uid_t uid,
                             USER_OFFLINE_REASON_TYPE reason) override {
    emit m_engine.userOffline(uid, reason);
  }
​
  virtual void onFirstLocalVideoFrame(int width, int height,
                                      int elapsed) override {
    emit m_engine.firstLocalVideoFrame(width, height, elapsed);
  }
​
  virtual void onFirstRemoteVideoDecoded(uid_t uid, int width, int height,
                                         int elapsed) override {
    emit m_engine.firstRemoteVideoDecoded(uid, width, height, elapsed);
  }
​
  virtual void onFirstRemoteVideoFrame(uid_t uid, int width, int height,
                                       int elapsed) override {
    emit m_engine.firstRemoteVideoFrameDrawn(uid, width, height, elapsed);
  }
​
 private:
  AgoraRtcEngine &m_engine;
};

我好像找到原因了RtcEngineContext注册的IRtcEngineEventHandler类而不是其子类AgoraRtcEngineEvent

谢谢,我再看看

class LiveObject : public QObject
{
public:
explicit LiveObject();
~LiveObject();
private:
static QMutex m_mutex;
IRtcEngine* m_rtcEngine;
QScopedPointer m_eventHandler;

LiveObject::LiveObject()
:m_rtcEngine(createAgoraRtcEngine())
,m_eventHandler(new EventHandler())
{
QMutexLocker autoLock(&m_mutex);
RtcEngineContext context;
context.eventHandler = m_eventHandler.get();//添加注册回调和事件
context.appId = APP_ID;
if (*context.appId == ‘\0’)
{
QMessageBox::critical(nullptr, (“提示”),
(“在使用演示之前,必须指定应用程序ID”));
}
m_rtcEngine->initialize(context);//初始化 IRtcEngine
}

这样就行了,已解决

赞!