Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. using typedef in Q_PROPERTY declarations
Forum Updated to NodeBB v4.3 + New Features

using typedef in Q_PROPERTY declarations

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 460 Views 2 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    Hi all -

    This question was raised in this post, but I want to get some more clarification on it.

    According to the docs, this "will confuse moc." Does this apply to any typedefs, even those using QObjects? If so, then this would be illegal:

    typedef QList<QUuid> ValveList;
    typedef QList<ValveList> ValveConfigurationList;
    Q_PROPERTY(ValveConfigurationList valveConfigurationList // etc
    

    And, so would even this:

    Q_PROPERTY(QList<ValveList> valveConfigurationList // etc
    

    So, really, I should do this:

    Q_PROPERTY(QList<QList<QUuid>> valveConfigurationList // etc
    

    True? I'm asking because I've been using typedefs in some of my Q_PROPERTY statements and they seem to work, but I'd like to know if I'm laying landmines for myself.

    Thanks...

    Axel SpoerlA 1 Reply Last reply
    0
    • mzimmersM mzimmers

      @Axel-Spoerl interesting. It sounds like the behavior can be unpredictable, so I think I'm going to go with #defines instead of typedefs, just to be sure.

      Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by Axel Spoerl
      #4

      @mzimmers
      My grandpa knew everything about WW2, I will tell my grandchildren everything about 6510 Assembler by the fireplace. But as I exceed the age of 50, I tend to forget more recent things that I don't use every day. Forgive me, that this was the case in the morning. Here is the precise answer that I owe you:

      1. Registering Metatypes
        As long as you don't need QMetaTypeto find out, what's the const char*key of a property, your're fine.
        If you want to register a meta type, so it can be found by someone not knowing your custom type, go by the following:
      typedef QList<QString> MyStringList;
      Q_DECLARE_METATYPE(MyStringList);
      qRegisterMetaType<MyStringList>("MyStringList");
      
      1. Custom Types
        If you want to use a custom type in a Q_PROPERTY, just make sure operator==and operator!=are nicely implemented.

      2. Pointers
        Pointers actually work nicely in Q_PROPERTY. You look like a guy to me, who implements clean ownership and thread safe objects where necessary. So I'll spare you the hints, that would just make me look smarter than I am :-)

      Software Engineer
      The Qt Company, Oslo

      1 Reply Last reply
      2
      • mzimmersM mzimmers

        Hi all -

        This question was raised in this post, but I want to get some more clarification on it.

        According to the docs, this "will confuse moc." Does this apply to any typedefs, even those using QObjects? If so, then this would be illegal:

        typedef QList<QUuid> ValveList;
        typedef QList<ValveList> ValveConfigurationList;
        Q_PROPERTY(ValveConfigurationList valveConfigurationList // etc
        

        And, so would even this:

        Q_PROPERTY(QList<ValveList> valveConfigurationList // etc
        

        So, really, I should do this:

        Q_PROPERTY(QList<QList<QUuid>> valveConfigurationList // etc
        

        True? I'm asking because I've been using typedefs in some of my Q_PROPERTY statements and they seem to work, but I'd like to know if I'm laying landmines for myself.

        Thanks...

        Axel SpoerlA Offline
        Axel SpoerlA Offline
        Axel Spoerl
        Moderators
        wrote on last edited by
        #2

        @mzimmers
        Property values become QVariants. In all honesty, I have had cases where it worked and where it didn’t. I don’t remember everything from the top of my head, but I mostly test if wrapping and unwrapping with a QVariant works. qRegisterMetaType() can be of value if it doesn’t. Sticking pointers into a property and throwing it over thread fences, has learned me a lesson in pain.

        Software Engineer
        The Qt Company, Oslo

        mzimmersM 1 Reply Last reply
        2
        • Axel SpoerlA Axel Spoerl

          @mzimmers
          Property values become QVariants. In all honesty, I have had cases where it worked and where it didn’t. I don’t remember everything from the top of my head, but I mostly test if wrapping and unwrapping with a QVariant works. qRegisterMetaType() can be of value if it doesn’t. Sticking pointers into a property and throwing it over thread fences, has learned me a lesson in pain.

          mzimmersM Offline
          mzimmersM Offline
          mzimmers
          wrote on last edited by
          #3

          @Axel-Spoerl interesting. It sounds like the behavior can be unpredictable, so I think I'm going to go with #defines instead of typedefs, just to be sure.

          Axel SpoerlA 1 Reply Last reply
          0
          • mzimmersM mzimmers

            @Axel-Spoerl interesting. It sounds like the behavior can be unpredictable, so I think I'm going to go with #defines instead of typedefs, just to be sure.

            Axel SpoerlA Offline
            Axel SpoerlA Offline
            Axel Spoerl
            Moderators
            wrote on last edited by Axel Spoerl
            #4

            @mzimmers
            My grandpa knew everything about WW2, I will tell my grandchildren everything about 6510 Assembler by the fireplace. But as I exceed the age of 50, I tend to forget more recent things that I don't use every day. Forgive me, that this was the case in the morning. Here is the precise answer that I owe you:

            1. Registering Metatypes
              As long as you don't need QMetaTypeto find out, what's the const char*key of a property, your're fine.
              If you want to register a meta type, so it can be found by someone not knowing your custom type, go by the following:
            typedef QList<QString> MyStringList;
            Q_DECLARE_METATYPE(MyStringList);
            qRegisterMetaType<MyStringList>("MyStringList");
            
            1. Custom Types
              If you want to use a custom type in a Q_PROPERTY, just make sure operator==and operator!=are nicely implemented.

            2. Pointers
              Pointers actually work nicely in Q_PROPERTY. You look like a guy to me, who implements clean ownership and thread safe objects where necessary. So I'll spare you the hints, that would just make me look smarter than I am :-)

            Software Engineer
            The Qt Company, Oslo

            1 Reply Last reply
            2
            • mzimmersM mzimmers has marked this topic as solved on

            • Login

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