我有两个名为 IPCBase 和 DispatchData 的类。现在我想将 QDataStrean Object drom IPCBase 传递给 DispatchData。首先,我尝试使用 Connect Statement 直接发送它。但它给出了错误,例如 QDataStream 对象未在 QRegisterMatatype 中注册。
编辑::我也参考了这个链接
所以我做了类似的事情
typedef QDataStream* myDataStrem;
Q_DECLARE_METATYPE(myDataStrem)
然后在另一个类中连接语句(DispatchData)
connect(mpThrIPCReceiver, SIGNAL(dispatchReadData(const int&, myDataStrem)),
this, SLOT(onIPCDataReceived(const int&, myDataStrem)));
onIPCDataReceived Slot
void DispatchData::onIPCDataReceived(const int& msgType, myDataStrem dataReceived)
{
// dataReceived >> str1; Here it is giving error
// qDebug()<<"is"<<str1;
MemberFuncPointer f = mIPCCommandMapper.value(msgType);
(this->*f)(*dataReceived);
//This is function pointer which will rout it to respective function depending on the Message type.
然后它会来到这里
void DispatchData::onStartCountingCycle(QDataStream &dataReceived)
{
int data = 0;
dataReceived >> data; //Here it is crashing
//Giving error like
//pure virtual method called
//terminate called without an active exception
// I have debugged it and here dataReceived is becoming Readonly.
}