PDA

View Full Version : Renaming multidimensional QLists



mobucl
16th December 2010, 17:03
Hi, Im both new to QT and to C++ (coming from matlab). I have been writing some code using QList containers in QT, however i have a question regarding naming of these. For example here i have a 3D QList which i initialize and then add stuff to:

QList < QList <QList<float> > >xyz; //initialize
xyz << QList<QList<float> > (); xyz << QList<QList<float> >();
xyz[0] << QList<float>();xyz[0] << QList<float>();xyz[0] << QList<float>(); //element 1
xyz[1] << QList<float>();xyz[1] << QList<float>();xyz[1] << QList<float>();
//element 2
xyz[0][0] << 0 << 0 << 0.5 << 0.5; //atom1 x
xyz[0][1] << 0 << 0.5 << 0 << 0.5; //atom1 y
xyz[0][2] << 0 << 0.5 << 0.5 << 0; //atom1 z
xyz[1][0] << 0.5 << 0.5 << 0 << 0; //atom2 x
xyz[1][1] << 0.5 << 0 << 0.5 << 0; //atom2 y
xyz[1][2] << 0.5 << 0 << 0 << 0.5; //atom2 z
This is great (although as a side point does anyone know a better way of initializing as this is alot of code!!) as i can now asses all my X,Y and Z data from both elements easily. BUT as i progress it will become difficult to keep up with what is where!

So can i assign names to each Qlist and refer to them using some code similar to structures (in matlab)

i.e. xyz[0] = 'element1' and xyz[0][0] = 'x' so:

xyz.element1.x = accesses this data

Thanks in advance,

Matt

tbscope
16th December 2010, 17:13
You can use structs and classes with QList

wysota
16th December 2010, 22:40
How about just using QVector<QVector3D>?

mobucl
17th December 2010, 09:04
Many thanks both wysota and tbscope, I will look at both of these! Thanks for helping a beginner!