Qt QSharedMemory and QDataStream



我想使用qsharedmemory进行共享内存。因此,我正在尝试使用QDataStream读取/编写自定义类。但是我不知道如何覆盖双重指针(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;
}

使用DeReference操作员。

示例:

unsigned char** dbRGB;
unsigned char* queryRGB;
in >> *dbRGB; // note the asterisk before 'dbRGB'

相关内容

  • 没有找到相关文章

最新更新