full solution of q_invokable and InvokeMethod usage
Please respect original works and translations. Reproduced please maintain the integrity of the article, and in the form of hyperlinks to the original author address http://blog.csdn.net/changsheng230, convenient for other friends to ask questions and correct me.
In a brief discussion of Qt Quick Macro, we will introduce the const char * Member,
- qgenericreturnargument ret, qgenericargument val0 = qgenericargument (0), ...)
The use of InvokeMethod is to attempt to invoke the object Obj method member (note that member can be a signal or a slot), how member can be called, then returns True, otherwise false. The Qmetaobject::invokemethod can be an asynchronous call or a synchronous call. It depends on how it's connected. Qt::D irectconnection, synchronous call, if "MethodName",
- Q_arg (Type1, arg1),
- Q_arg (type2, arg2));
The above call is an asynchronous call. Note that because the parameters shown above need to be hard-copied at the time of the build event, the class for the parameter's custom type needs to provide a common constructor, destructor, and copy constructor. It must also be used to register QT c++/qml mixed programming, cross-threading programming ,Qt/HTML5 mixed programming , and widely used.
Qt meta-object system. Consider using Qt 4.7 in QML
- Import Shapes 5.0 //Custom modules
- Item {
- width:300; height:200
- Ellipse {
- x:50; y:35; width:200; height:100
- Color: "Blue"
- Mousearea {
- Anchors.fill:parent
- //Call the Randomcolor method defined in C + +
- OnClicked:parent.color = Parent.randomcolor ()
- }
- }
- }
-
In order for the above QML code to successfully call the Randomcolor () function defined by this code, the most critical point is Randomcolor method with q_invokable modification.
View Plainprint?
- #include <qdeclarativeitem >
- Class Ellipseitem: Public Qdeclarativeitem
- {
- Q_object
- Public
- Q_invokable qcolor Randomcolor () const;
- ...
- }
For more details, please see my other blog post: QML and C + + mixed programming use
Use in cross-threading programmingHow do we invoke the Qobject method that stops at other lines thread? Event loops and Threads
the Qt Service Framework is the method and q_invokeble to implementOne of the most common ways to interact with servicer is as follows:
View Plainprint?
- Qservicemanager Manager; Qobject *storage;
- Storage = Manager.loadinterface ("Com.nokia. If (storage) Qmetaobject::invokemethod (storage, "DeleteFile", Q_arg (QString, "/tmp/readme.txt")) ;
The above code invokes the DeleteFile () method of the file store object through the InvokeMethod method provided by the service's meta-object. The client does not need to know the type of the object and therefore is not linked to the specific service library. Of course, the DeleteFile method on the service side must be marked as q_invokeble to be able to be recognized by the meta-object system.
Method and property to communicate, just like local objects. Services can be set up to be shared between clients, or for a client. note that the method only supports cross-threading. is a step into the service/customer segment communication (Image from Nokia Forum). Here we can see clearly,invokable
About Qt Service Framework Documentation
Full solution of q_invokable and InvokeMethod usage