Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Dynamic properties
Forum Updated to NodeBB v4.3 + New Features

Dynamic properties

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 3.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maherali
    wrote on last edited by
    #1

    Hi
    I've read about the dynamic properties in Qt
    I know there is something in .NET for what is called the Reflection namespace, using this name space we were able to probe information about class in the runtime.

    My question is: if you have experience in Qt where did you used the dynamic property feature in practice?

    Thanks

    life is just lines of code

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      You can use that to store additional info for an object. I rarely used it, but, e.g. If you want to connect input objects (LineEdit, ComboBox, etc) with process values you could store the process value name, address in a dynamic property of the input widget, so you don't have to create some custom mapping in source code.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        It can be a handy mechanism to attach information to an object that does not provide its own API for that. I have used it, but it is not something to rely on too much IMHO. Often, it is a quick-and-dirty way to add properties to an object that could (and perhaps should?) be added to the object using subclassing instead. However, that is not always trivial or even desireable, and in such cases this can be a handy escape route.

        The main downsides are, IMO:

        that you cannot see that such a property is/can be attached at runtime because it does not show up in the class definition (other than the generic method in QObject itself, ofcourse), and that makes it harder to understand the source;

        that it is a non-typesave way to work (I don't considder QVariant nicely type save).

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maherali
          wrote on last edited by
          #4

          Thanks Gerlf and Andre for information

          The only logical and frequent use has just come up in my mind: it's like a tag associated with each object, actually I remember there was a tag in .NET

          Anyway thanks for your replies.

          life is just lines of code

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            [quote author="Andre" date="1320226863"]Often, it is a quick-and-dirty way to add properties to an object that could (and perhaps should?) be added to the object using subclassing instead.[/quote]

            There are situations where you cannot use subclasses, for example QApplication and QDeclarativeView in conjunction with the Harmattan Booster / MDeclarativeCache. In such situations dynamic properties are actually quite handy to "attach" some data to objects - which becomes even globally accessible when attached to QApplication.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved