Const double * to QVector<double>
-
Hello,
i got a pointer to an array with double values. But i need the values in a QVector.const double *array = externObject->getArray(); QVector<double> myArray = array;// how to solve this problem
I can do a for loop, but it doesn't look very well:
QVector<double> myArray; for(int i = 0; i < externObject->arrayCount(); i++) { myArray << externObject->getArray()[i]; }
Is there a better way to do that?
Thanks
-
Hello,
i got a pointer to an array with double values. But i need the values in a QVector.const double *array = externObject->getArray(); QVector<double> myArray = array;// how to solve this problem
I can do a for loop, but it doesn't look very well:
QVector<double> myArray; for(int i = 0; i < externObject->arrayCount(); i++) { myArray << externObject->getArray()[i]; }
Is there a better way to do that?
Thanks
int count = externObject->arrayCount(); const double * array = externObject->getArray(); QVector<double> myArray(count); ::memcpy(myArray.data(), array, count * sizeof(double));
-
Hello,
i got a pointer to an array with double values. But i need the values in a QVector.const double *array = externObject->getArray(); QVector<double> myArray = array;// how to solve this problem
I can do a for loop, but it doesn't look very well:
QVector<double> myArray; for(int i = 0; i < externObject->arrayCount(); i++) { myArray << externObject->getArray()[i]; }
Is there a better way to do that?
Thanks
@beecksche
you implicitly already showed that it isn't possible with an assignment operator only. (Edit: but i guess that's not what you were after afterall?)
In your loop you usedarrayCount()
to determine the item count. How would you do it in the assignment operator?