Results 1 to 3 of 3

Thread: Variable variable names

  1. #1
    Join Date
    Apr 2014
    Posts
    116
    Thanks
    8
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Variable variable names

    Hi,

    are there variable variable names in Qt? I tried to search for it but I did not really know how to and so I found nothing. I have a php background and there I could do this. Can I do something similar in Qt?

    My problem is that I have a class with several properties and a variable that tells me which property is interesting at the moment. In stead of writing a lot of if statements I would rather directly go the value by stating className.interestingValue.

    Here is an example. I got the class car. Within that class have several properties like car.door = 4 and car.maxSpeed = 200 etc. On the other hand I got a variable testValue = "door". How can I get the number of doors now from my class car object without using if-statements? Like log.append("Your result is: "+audi.testValue.toStr());

    Thanks

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,464
    Thanked 272 Times in 267 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Variable variable names

    Read about property system

  3. #3
    Join Date
    Oct 2012
    Posts
    132
    Thanks
    10
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Variable variable names

    You can also use QMap or std::map.

Similar Threads

  1. A variable in setTable()
    By thefatladysingsopera in forum Newbie
    Replies: 6
    Last Post: 2nd August 2011, 09:37
  2. variable
    By Atuti2009 in forum Qt Programming
    Replies: 8
    Last Post: 18th November 2009, 10:04
  3. QTScript - checking variable names?
    By android_ in forum Qt Programming
    Replies: 1
    Last Post: 15th June 2009, 19:40
  4. Entering variable in db
    By subratatamal in forum Qt Programming
    Replies: 1
    Last Post: 13th December 2008, 18:50
  5. Variable question
    By MarkoSan in forum General Programming
    Replies: 4
    Last Post: 15th March 2007, 15:59

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.