PDA

View Full Version : Conversion of QLists and Qvectors from floats to doubles



mobucl
17th May 2011, 11:20
Hi, this may be a simple question but i have looked arround and havent seen a direct answer. I have two situations, the first is:

QVector<float> test // contains a series of floating point numbers

BUT how can i convert these to QVector<double> easily. I was hoping for a simple test.toDouble() but this seems to not be the case.

Second - a bit more complex? can i convert a QList<Qlist<float> > in a similiar manner Here is some code:



QList<QList<float> > out; // create the variable discussed above

for (int i = 0; i< 10; i++) //create 10 Qlists to hold values
{
out << QList<float>();
}
for (int ii = 0; ii<10;ii++ // fill the Qlists with some values
{
out[ii] << somevalues[ii]
}

QVector<double> test;
test = out[1].toDouble // trying to take all the elements in the first Qlist of floats
// and ouput them to a QVector of doubles ->DOESNT WORK



Hope this makes sense!

Thanks

Matt

stampede
17th May 2011, 11:37
I was hoping for a simple test.toDouble()
QList and QVector are supposed to be generic containers, so they have no methods related to stored datatype. If you want to convert, loop and convert the numbers yourself. Or make your own FloatList, FloatVector, DoubleList, etc. classes, where you can implement conversion methods toFloat(), toDouble() and reuse it in the rest of your code ( and maybe in your other projects ).

mobucl
17th May 2011, 11:47
thanks stampede - i will give this a try!