Q_PROPERTY(QVariantList sortCriteries WRITE setSortCriteries)
I am getting build warning:
warning : Property declaration sortCriteries has no READ accessor function or associated MEMBER variable. The property will be invalid.
I have tried replacing it with the keyword MEMBER but im getting error that MEMBER keyword is unknown or not recognized
Q_PROPERTY(QVariantList MEMBER sortCriteries WRITE setSortCriteries)
i dont want to make a READ or getter function as it has no use, any idea on how to approach this?
Im using 5.15, any idea?
Your property declaration with MEMBER should look like this:
Q_PROPERTY(QVariantList sortCriteries MEMBER sortCriteriesMember WRITE setSortCriteries)
(Where sortCriteriesMember is obviously the name of the member in your class, which can be different from the property name)
That said, if you only want to be able to write, you can also consider a Q_INVOKABLE:
Q_INVOKABLE void setSortCriteries(const QVariantList& value);
Related
I have some data types defined as enum in a namespace.
I wanted to use Q_PROPERTY, that would return the data types...
But I get error:
'staticMetaObject' is not a member of 'blah'
So it seems, if I want to create my own types, and use them in functions that are mentioned in Q_PROPERTY, they must be inside a class inheriting QObject and declaring the Q_OBJECT macro ? Isn't that a lot of overhead ?
is there an alternative ?
Maybe you are searching for Q_GADGET? It generates metadata for non QObject derived types. You can have Q_PROPERTY and Q_INVOKABLE within a gadget.
And yes, there is quite a lot of overhead, if you don't need QObject don't use it. It is like 160 bytes to begin with.
in this line
<mx:Label x="132" y="105" id="statusText"/>
I get an error -
Attempting to initialize inherited property 'statusText' of type
'spark.components.supportClasses.TextBase' with value of incompatible
type 'mx.controls.Label'.
Im using flex 4.6
You get this error when you declare something in mxml with id which is already used in the superclass.
Normally it will just use your definition, overriding superclass one if it exists.
But in you code type of your definition for this id and superclass definition for this id are different, so you get this error.
As I see, it was not your intention to override superclass definition, so you shall just rename id for your label.
I am using QJson to serialize a QObject-derived class. I am able to serialize the class itself without any problems, but when it comes to one of its members, I am having a bit of trouble.
The class is named CProject and it contains a property files which is defined as:
QList<CProjectFile> files;
When serializing an instance of CProject, I get a message in the console:
QMetaProperty::read: Unable to handle unregistered datatype 'QList<CProjectFile>' for property 'CProject::files'
I read somewhere that I have to register the datatype, so I added the following after the declaration of CProject:
Q_DECLARE_METATYPE(QList<CProjectFile>)
...and when that did nothing, I added:
qRegisterMetaType< QList<CProjectFile> >();
Nothing is working. What am I doing wrong?
I don't know how QJson works but perhaps it requires stream operators. Try as below after declaration of CProjectFile class
class CProjectFile
{
...
};
Q_DECLARE_METATYPE(CProjectFile)
qRegisterMetaType<CProjectFile>("CProjectFile");//Do this if you need signal/slots
qRegisterMetaTypeStreamOperators<QList<CProjectFile> >("CProjectFileList");
See also QT Doc for stream operators
I have the following files:
model.as
clint.mxml
in clint.mxml I have the following line:
<s:Group id='clint1' x="model.locationX">
...
in the model.as I have a getter:
[bindable(event="locationXChanged"))
function get locationX () : int {
return ...
}
My problem is that I need to know within the getter locationX that the id of the object that is getting the id is clint1 (The object id in the mxml).
The result of a getter should not depend on which object it is called from. I guess your getter should not be a getter and should maybe take a clintId as argument.
You can use this to refer to the current component. You can use 'this.id' to find out the component's name. More info on id property.
However, I'm getting mixed signals from your question and the question's title. Are you asking for the id of the binding target inside the binding source? Implementing that would add dependencies to your components thus harming their ability for reuse.
I've have a workflow whose root activity is a custom NativeActivity with a public InArgument called XmlData. When I try and use this argument in a child If activity I get the following error using XmlData within the condition:
'XmlData' is not declared. It may be inaccessible due to its protection level
My properties look like this:
public Activity Body {get;set;}
public InArgument<CustomObj> XmlData {get;set;}
and this is the CacheMetadata method:
protected override void CacheMetadata(NativeActivityMetadata metadata)
{
var runtime = new RuntimeArgument("XmlData",typeof(CustomObj),ArgumentDirection.In,true);
metadata.Bind(this.XmlData,runtime);
metadata.AddArgument(runtime);
metadata.AddChild(Body);
}
I'm adding the argument inside CacheMetadata using the metadata.AddArgument method, and I've tried adding the child property it has using both AddChild and AddImplementationChild.
If I replace my custom activity with an ActivityBuilder and use code to create a DynamicActivityProperty then the condition can be compiled successfully, so I don't see what I'm missing when I use my own code.
There are 3 possible solutions I can think of, one is daft, one is hacky and the other vaguely sensible.
Solution 1 (the daft one)
Promote the RuntimeArgument to a private readonly member and swap the Bind and AddArgument calls around, I've had a few random occurances where this has helped.
Solution 2 (the very hacky one)
You can always put the values in a named property on the context and pull it out in the child
Solution 3 (the sensible one)
If you want to pass the InArgument to a child, bind it to a variable and bind the child to the variable.
Any of those help?
John