Question about Class and Pointers to them.
-
Hello my Qt Guru's
It's probably a trivial question but I'm restyling with it a bit and i cant still find solution.
Idea of my program is Load data from file ( 3d object as *obj or *lwo ) then do some calculation modification on loaded data, and strip it to simple 3d vertex coordinates and line definitions then generate result file with this proceed data.
Sounds trivial i already wrote something like that in C but is a console app.
I wand now a GUI and maybe when i get on with Qt i will add some editing options, but for now noobe question time.My problem is a Class and passing it to other functions, I trying to store loaded data into a class and then pass them by pointer, to this class.
I'm created a very simple code illustrating problem instead of pasting 100- lines of garbage code.@class TestClass
{private:
int someData;
QVector<QVector3D> someComplexData;public:
TestClass();//simply setters void set_Data(int dat) { someData = dat; } void add_vertex (QVector3D Vertex) { someComplexData.append (Vertex); } //simply getters int get_Data() { int databack; databack = someData; return(databack); } float get_Vertex_x (int vertex_no) { QVector3D rVertex; float rX; rVertex = someComplexData.at (vertex_no); rX = rVertex.x (); return(rX); } // similar getters for Y and Z coordinates
};@
and Main Window there a two push buttons one to load one to do something,.
@MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::on_Load_D_clicked()
{
// normaly i wil load data from file//
int loaded_int = 100;
QVector3D Point3d;TestClass *myClass = new TestClass; myClass->set_Data (loaded_int); // generating some points instead of load them for(int i=0; i<4 ; i++) { Point3d.setX (0.5 +i); Point3d.setY (4.01 *i); Point3d.setZ (10.5 -(2*i)); myClass->add_vertex (Point3d); } // geting some of them back int A; float X_cords; A = myClass->get_Data (); X_cords = myClass->get_Vertex_x (1); qDebug() << A; qDebug() << X_cords; // ok points are in object in class :)
}
void MainWindow::on_Do_something_clicked()
{
/*
* Main question is how acces ( object ) data from TestClass called by by other function
* or how pass a pointer to this class
*/
}
@Q 1:
How pass a pointer o reference to already decelerated instance of class to other function
Q 2:
How declarate function in mainWindow.h in "private slots:" for passing a pointer to class, like that
@...
void some_function()
{
TestClass *myClass = new TestClass;
// add some data to the classproces_data(myClass); // call other function passing pointer to class
}
void proces_data(TestClass *passedClass)
{
passedClass->do_something();
}
...@Q 3.
if is a possibility to return a whole array. how to do this ? instead of calling getters for each parameter.
@return QVectro<QVector3D> (pointer to vector);@or just one dimensional array
@return QVector3D (v3d);@