×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    18

    How to Convert a QStringList into an array of doubles??

    Hi everyone!

    Can any body tell me How to Convert a QStringList into an array of doubles???

    e.g. I have a QStringList: 1 2 3 4 5 6 7 8 1 9
    The Code that I've tried is as under:

    QString str = "1 2 3 4 5 6 7 8 1 9";
    QList<QString> list;
    list = str.split(QRegExp("\\s+"),QString::SkipEmptyParts);

    double n[list.size()];

    QList<QString>::iterator i;
    int j; QString temp;
    for(i = list.begin(); i != list.end(); ++i)
    {
    temp = *i;
    j = list.indexOf(temp);
    n[j] = temp.toDouble();
    }

    for(int j=0;j<list.size();j++)
    qDebug()<<n[j];


    But the out put is as follows:
    1
    2
    3
    4
    5
    6
    7
    8
    6.952217e-308
    9

    I've tried java style iterator (while(i.hasNext)............) as well but same result..

  2. #2
    Super Contributor
    Join Date
    Jun 2006
    Location
    India
    Posts
    3,037

    Re: How to Convert a QStringList into an array of doubles??

    what would you like to achieve by this?

    you can also try like QList<double> or check for QMap also. it may he simple and helpful for you.
    Use [URL="http://qt.nokia.com/products/qt-quick/"]Qt-Quick[/URL] to make your application UI more attractive.

    [URL="http://store.ovi.com/content/271896"]http://store.ovi.com/content/271896[/URL] | [URL="http://store.ovi.com/content/276199"]http://store.ovi.com/content/276199[/URL] |[URL="http://store.ovi.com/content/276202"] http://store.ovi.com/content/276202[/URL] | [URL="http://store.ovi.com/content/280827"]http://store.ovi.com/content/280827[/URL]

  3. #3
    Registered User
    Join Date
    Mar 2012
    Posts
    18

    Re: How to Convert a QStringList into an array of doubles??

    I wanna use this in gui application. in which a user enters a list of doubles. I want to convert that text into an array of doubles for further processing.

  4. #4
    Registered User
    Join Date
    Sep 2011
    Posts
    449

    Re: How to Convert a QStringList into an array of doubles??

    Hi,

    for(i = list.begin(); i != list.end(); ++i)
    {
    temp = *i;
    j = list.indexOf(temp); // here indexOf returns always the first occurance of the item (temp here), so incase there are duplicates, this logic wont work.. hence its not working..
    n[j] = temp.toDouble();
    }


    So just use this and try ,

    for(j=0, i = list.begin(); i != list.end(); ++i, j++)
    {
    temp = *i;

    n[j] = temp.toDouble();
    }

  5. #5
    Registered User
    Join Date
    Mar 2012
    Posts
    18

    Re: How to Convert a QStringList into an array of doubles??

    Thanks kusumk!!
    It works..

Similar Threads

  1. Replies: 3
    Last Post: 2011-06-22, 15:21
  2. How to convert array of Objects into array of Strings?
    By elenora in forum Mobile Java General
    Replies: 2
    Last Post: 2011-06-12, 12:12
  3. Replies: 3
    Last Post: 2010-01-02, 15:02
  4. Array of 6 million doubles
    By stavrospapa in forum Symbian
    Replies: 2
    Last Post: 2008-11-02, 05:31
  5. How to Convert mid to byte array?
    By returnti in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2003-05-09, 18:23

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×