PDA

View Full Version : Sharing vectors between classes



dubstar_04
6th March 2014, 23:11
I have a pointcloud class that stores points:




class pointCloud : public QObject
{
Q_OBJECT
public:
explicit pointCloud(QObject *parent = 0);

signals:

public slots:

void addPoint(float x, float y, float z);

private:

struct point {

float x;
float y;
float z;

};


std::vector<point> points;
};





i create point cloud:

pointCloud pointcloud;

and filled the vector with points.

I now want to pass this vector to a QGLWidget for display.

Whats the best way to share this data?

Thanks,

Dubstar_04

ChrisW67
6th March 2014, 23:43
Any way that makes sense for your application and is valid C++ is good. There is not single "best" answer to a broad general question.

dubstar_04
7th March 2014, 10:49
I have tried passing the pointcloud object as a pointer and a reference and i couldn't get either to work.

would it be best to pass just the points vector?

The QGLWidget shouldn't alter the points data, just display it. i have read that a const vector by reference should be used, but i am a little out of my depth here.

Thanks for any tips,

Dubstar_04