// create a QVector3D object QVector3D vec(1.0, 2.0, 3.0); // set the X component to 4.0 vec.setX(4.0); // output the vector components to the console qDebug() << vec.x() << vec.y() << vec.z(); // output: 4 2 3
// create an array of QVector3D objects QVector3D vecs[] = { QVector3D(1.0, 0.0, 0.0), QVector3D(0.0, 1.0, 0.0), QVector3D(0.0, 0.0, 1.0) }; // loop over the array and set each X component to 2.0 for (int i = 0; i < 3; i++) { vecs[i].setX(2.0); } // output the vector components to the console for (int i = 0; i < 3; i++) { qDebug() << vecs[i].x() << vecs[i].y() << vecs[i].z(); // output: 2 0 0, 2 1 0, 2 0 1 }These examples use the Qt framework's QVector3D class, which is part of the QtCore library.