Results 1 to 4 of 4

Thread: How to convert string into const int ?

  1. #1
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    156
    Thanks
    47
    Qt products
    Qt4
    Platforms
    Windows

    Question How to convert string into const int ?

    How to convert string into const int ?

  2. #2
    Join Date
    Feb 2010
    Posts
    99
    Thanks
    31
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to convert string into const int ?

    Try this

    Qt Code:
    1. const int myInt=myString.toInt();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Apr 2010
    Location
    Singapore
    Posts
    156
    Thanks
    47
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to convert string into const int ?

    Quote Originally Posted by dpatel View Post
    Try this

    Qt Code:
    1. const int myInt=myString.toInt();
    To copy to clipboard, switch view to plain text mode 

    It works!

    But strangely if I do it the way as shown in code below, I will get error: assignment of read-only variable myInt .
    Qt Code:
    1. const int myInt = 0;
    2.  
    3. myInt = myString.toInt();
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2010
    Posts
    99
    Thanks
    31
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to convert string into const int ?

    That is an expected behavior, since consts can be assigned value only once. In your case you use your one chance when you assign 0 to it. After that it become read-only.

Similar Threads

  1. How to convert QString to const char*
    By fulin in forum Newbie
    Replies: 7
    Last Post: 9th May 2010, 23:25
  2. Replies: 1
    Last Post: 4th December 2009, 17:03
  3. how to format a number into a const width string ?
    By lovelypp in forum Qt Programming
    Replies: 3
    Last Post: 25th July 2008, 21:45
  4. convert from qstring to const char *
    By deepa.selvaraj in forum Qt Programming
    Replies: 3
    Last Post: 28th November 2007, 12:33
  5. How to convert a QString to const char *?
    By SkripT in forum Newbie
    Replies: 2
    Last Post: 10th March 2006, 10:56

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.