Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User Nujabrn's Avatar
    Join Date
    Mar 2010
    Posts
    16
    Hey forumnokia,

    Im trying to convert a qreal to a QString. I tried using the QString::setNum which is giving me an error. I added the simple code and error message i got, but can't figure out how to write and use the object.



    Also, if anyone knows another, maybe smarter way to convert a qreal to a QString, im very open for solutions.

  2. #2
    Nokia Developer Champion danhicksbyron's Avatar
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209
    QString::number

    Or,
    Code:
    string1.setNum(real1,'g', 6);

  3. #3
    Registered User Nujabrn's Avatar
    Join Date
    Mar 2010
    Posts
    16
    Quote Originally Posted by danhicksbyron View Post
    QString::number

    Or,
    Code:
    string1.setNum(real1,'g', 6);
    I can't call setNum from string1 (its a char). I tried creating a new string and use setNum but the error message tells me its an invalid conversion from 'char*' to 'char¨'.

  4. #4
    Nokia Developer Champion danhicksbyron's Avatar
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209
    Have you looked at the spec? Do you know the difference between a regular function and a static function? How do you expect to set a float value into a char?

  5. #5
    Registered User Zlatomir's Avatar
    Join Date
    May 2009
    Location
    Romania->Felnac
    Posts
    5
    Why do you use char array and don't use QString?

    If you really need char array you can use:
    Code:
    // string is a QString
    //and string.setNum(qrealVaribleName); //was used to get the string representation of qreal variable
    
    const char* str = string.toLatin1().data(); //valid until the QString goes out of scope or you modify the QString
    
    // you can copy the c-style string if you really need a copy (strcpy)
    Last edited by Zlatomir; 2010-12-14 at 19:20.

  6. #6
    Registered User Nujabrn's Avatar
    Join Date
    Mar 2010
    Posts
    16
    Quote Originally Posted by Zlatomir View Post
    Why do you use char array and don't use QString?

    If you really need char array you can use:
    Code:
    // string is a QString
    //and string.setNum(qrealVaribleName); //was used to get the string representation of qreal variable
    
    const char* str = string.toLatin1().data(); //valid until the QString goes out of scope or you modify the QString
    
    // you can copy the c-style string if you really need a copy (strcpy)
    Hi there, i don't have to use a char. I just thoght it was the only way to do it.
    Is there an easier way to convert a double to a String?

  7. #7
    Nokia Developer Champion danhicksbyron's Avatar
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209
    Is there an easier way to convert a double to a String?
    RTFM: http://doc.qt.nokia.com/4.7-snapshot....html#number-2

Similar Threads

  1. How to use QString::number
    By nokia-5530 in forum Qt
    Replies: 0
    Last Post: 2010-11-18, 20:25
  2. char to QString?
    By damodharan in forum Qt
    Replies: 4
    Last Post: 2010-07-20, 15:03
  3. exception occurs when converting QString to std::string
    By kimitake in forum [Archived] Qt SDKs and Tools
    Replies: 4
    Last Post: 2010-04-29, 17:08
  4. Rounding float/qreal numbers
    By danhicksbyron in forum Qt
    Replies: 3
    Last Post: 2010-03-13, 03:45

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved