Results 1 to 3 of 3

Thread: Conversion of QLists and Qvectors from floats to doubles

  1. #1
    Join Date
    Dec 2010
    Posts
    31
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Conversion of QLists and Qvectors from floats to doubles

    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:


    Qt Code:
    1. QList<QList<float> > out; // create the variable discussed above
    2.  
    3. for (int i = 0; i< 10; i++) //create 10 Qlists to hold values
    4. {
    5. out << QList<float>();
    6. }
    7. for (int ii = 0; ii<10;ii++ // fill the Qlists with some values
    8. {
    9. out[ii] << somevalues[ii]
    10. }
    11.  
    12. QVector<double> test;
    13. test = out[1].toDouble // trying to take all the elements in the first Qlist of floats
    14. // and ouput them to a QVector of doubles ->DOESNT WORK
    To copy to clipboard, switch view to plain text mode 

    Hope this makes sense!

    Thanks

    Matt
    Last edited by high_flyer; 17th May 2011 at 10:39. Reason: code tags

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Conversion of QLists and Qvectors from floats to doubles

    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 ).

  3. The following user says thank you to stampede for this useful post:

    mobucl (17th May 2011)

  4. #3
    Join Date
    Dec 2010
    Posts
    31
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Conversion of QLists and Qvectors from floats to doubles

    thanks stampede - i will give this a try!

Similar Threads

  1. QList of QLists
    By m15ch4 in forum Newbie
    Replies: 12
    Last Post: 16th October 2013, 22:36
  2. Renaming multidimensional QLists
    By mobucl in forum Newbie
    Replies: 3
    Last Post: 17th December 2010, 09:04
  3. QPainter::drawPixmap with floats ?
    By christophe.daudin in forum Qt Programming
    Replies: 8
    Last Post: 20th October 2009, 10:19
  4. help using QLists as data in QwtPlotCurve
    By esorensen in forum Qwt
    Replies: 1
    Last Post: 11th July 2008, 19:52
  5. QList of Qlists?
    By markcole in forum Qt Programming
    Replies: 6
    Last Post: 8th July 2008, 05:44

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.