using typedef in Q_PROPERTY declarations
-
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-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.
@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:- Registering Metatypes
As long as you don't needQMetaType
to find out, what's theconst 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");
-
Custom Types
If you want to use a custom type in a Q_PROPERTY, just make sureoperator==
andoperator!=
are nicely implemented. -
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 :-)
- Registering Metatypes
-
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...
@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. -
@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.@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-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.
@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:- Registering Metatypes
As long as you don't needQMetaType
to find out, what's theconst 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");
-
Custom Types
If you want to use a custom type in a Q_PROPERTY, just make sureoperator==
andoperator!=
are nicely implemented. -
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 :-)
- Registering Metatypes
-
M mzimmers has marked this topic as solved on