Qt QSharedMemory 和 QDataStream
Qt QSharedMemory and QDataStream
我想使用 QSharedMemory 创建共享内存。
所以,我正在尝试使用 QDataStream read/write 我的自定义 类。
但我不知道如何覆盖双指针(float **)。
(我之所以使用双指针是因为opencv cv::Mat,如果有比我想要的更好的方法,请推荐)
class ObservationData
{
private:
int m_nCameras;
cv::Mat** m_matDBRGB;
cv::Mat* m_matQueryRGB;
unsigned char** dbRGB;
unsigned char* queryRGB;
int row, col;
int m_recogIdx;
public:
ObservationData();
~ObservationData();
void setNumCameras(const int nCameras);
int getNumCameras() const;
void setDB_RGB(const unsigned char** rgb);
unsigned char** getDB_RGB() const;
void setQuery_RGB(const unsigned char* rgb);
unsigned char* getQuery_RGB() const;
void setRow(const int row);
void setCol(const int col);
int getRow() const;
int getCol() const;
}
和 cpp 文件:
void ObservationData::setNumCameras(const int nCameras)
{
this->m_nCameras = nCameras;
}
int ObservationData::getNumCameras() const
{
return this->m_nCameras;
}
void ObservationData::setDB_RGB(const unsigned char** rgb)
{
std::memcpy(this->dbRGB, rgb,
sizeof(unsigned char)
* this->row * this->col * 3 * this->m_nCameras
);
}
unsigned char** ObservationData::getDB_RGB() const
{
return this->dbRGB;
}
void ObservationData::setQuery_RGB(const unsigned char* rgb)
{
std::memcpy(this->queryRGB, rgb,
sizeof(unsigned char)
* this->row * this->col * 3
);
}
unsigned char* ObservationData::getQuery_RGB() const
{
return this->queryRGB;
}
void ObservationData::setRow(const int row)
{
this->row = row;
}
void ObservationData::setCol(const int col)
{
this->col = col;
}
int ObservationData::getRow() const
{
return this->row;
}
int ObservationData::getCol() const
{
return this->col;
}
QDataStream &operator<<(QDataStream &out, const ObservationData &ob)
{
out << ob.getDB_RGB() << ob.getQuery_RGB();
return out;
}
QDataStream &operator>>(QDataStream &in, ObservationData &ob)
{
unsigned char** dbRGB;
unsigned char* queryRGB;
//in >> dbRGB >> queryRGB; ///// ERROR
ob.setDB_RGB(dbRGB);
ob.setQuery_RGB(queryRGB);
return in;
}
示例:
unsigned char** dbRGB;
unsigned char* queryRGB;
in >> *dbRGB; // note the asterisk before 'dbRGB'
我想使用 QSharedMemory 创建共享内存。 所以,我正在尝试使用 QDataStream read/write 我的自定义 类。 但我不知道如何覆盖双指针(float **)。
(我之所以使用双指针是因为opencv cv::Mat,如果有比我想要的更好的方法,请推荐)
class ObservationData
{
private:
int m_nCameras;
cv::Mat** m_matDBRGB;
cv::Mat* m_matQueryRGB;
unsigned char** dbRGB;
unsigned char* queryRGB;
int row, col;
int m_recogIdx;
public:
ObservationData();
~ObservationData();
void setNumCameras(const int nCameras);
int getNumCameras() const;
void setDB_RGB(const unsigned char** rgb);
unsigned char** getDB_RGB() const;
void setQuery_RGB(const unsigned char* rgb);
unsigned char* getQuery_RGB() const;
void setRow(const int row);
void setCol(const int col);
int getRow() const;
int getCol() const;
}
和 cpp 文件:
void ObservationData::setNumCameras(const int nCameras)
{
this->m_nCameras = nCameras;
}
int ObservationData::getNumCameras() const
{
return this->m_nCameras;
}
void ObservationData::setDB_RGB(const unsigned char** rgb)
{
std::memcpy(this->dbRGB, rgb,
sizeof(unsigned char)
* this->row * this->col * 3 * this->m_nCameras
);
}
unsigned char** ObservationData::getDB_RGB() const
{
return this->dbRGB;
}
void ObservationData::setQuery_RGB(const unsigned char* rgb)
{
std::memcpy(this->queryRGB, rgb,
sizeof(unsigned char)
* this->row * this->col * 3
);
}
unsigned char* ObservationData::getQuery_RGB() const
{
return this->queryRGB;
}
void ObservationData::setRow(const int row)
{
this->row = row;
}
void ObservationData::setCol(const int col)
{
this->col = col;
}
int ObservationData::getRow() const
{
return this->row;
}
int ObservationData::getCol() const
{
return this->col;
}
QDataStream &operator<<(QDataStream &out, const ObservationData &ob)
{
out << ob.getDB_RGB() << ob.getQuery_RGB();
return out;
}
QDataStream &operator>>(QDataStream &in, ObservationData &ob)
{
unsigned char** dbRGB;
unsigned char* queryRGB;
//in >> dbRGB >> queryRGB; ///// ERROR
ob.setDB_RGB(dbRGB);
ob.setQuery_RGB(queryRGB);
return in;
}
示例:
unsigned char** dbRGB;
unsigned char* queryRGB;
in >> *dbRGB; // note the asterisk before 'dbRGB'