Full solution of q_invokable and InvokeMethod usage

Source: Internet
Author: User

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?
      1. #include <qdeclarativeitem >
      2. Class Ellipseitem: Public Qdeclarativeitem
      3. {
      4. Q_object
      5. Public
      6. Q_invokable qcolor Randomcolor () const;
      7. ...
     

    For more details, please see my other blog post: QML and C + + mixed programming use

    Use in cross-threading programming

    How 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 implement

    One of the most common ways to interact with servicer is as follows:

    View Plainprint?
      1. Qservicemanager Manager; Qobject *storage;
      2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.