Results 1 to 3 of 3

Thread: Get value for variable name defined as string

  1. #1
    Join Date
    May 2008
    Location
    Spain
    Posts
    92
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Get value for variable name defined as string

    Hello,

    I would like to known if it possibe to obtain a value of variable defined as string in a Qt program.

    For example:

    char* varname[] = {"test", "dog"}
    test = 5;
    dog = 8;

    Can I obtain value of varname[1]???

    Best regards.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Get value for variable name defined as string

    You can use QHash or QMap for that.
    Qt Code:
    1. QHash<QString, int> hash;
    2. QString key = "foo";
    3. hash[key] = 100;
    To copy to clipboard, switch view to plain text mode 

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

    webquinty (18th November 2009)

  4. #3
    Join Date
    May 2008
    Location
    Spain
    Posts
    92
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Get value for variable name defined as string

    Quote Originally Posted by Lykurg View Post
    You can use QHash or QMap for that.
    Qt Code:
    1. QHash<QString, int> hash;
    2. QString key = "foo";
    3. hash[key] = 100;
    To copy to clipboard, switch view to plain text mode 
    Thanks a lot, I am going to test it.

Similar Threads

  1. Replies: 0
    Last Post: 18th February 2009, 13:31
  2. String operations, printing to stdout
    By Cruz in forum Newbie
    Replies: 3
    Last Post: 20th January 2009, 15:30
  3. saving a c string of variable length in a shared memory?
    By nass in forum General Programming
    Replies: 4
    Last Post: 3rd January 2007, 14:40
  4. Create pixmap image from string
    By Morea in forum Qt Programming
    Replies: 5
    Last Post: 17th November 2006, 16:38
  5. Replies: 25
    Last Post: 15th January 2006, 00:53

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.