Accessing QML objects from C++

蹲街弑〆低调 提交于 2019-12-10 18:06:44

问题


Following is a code written to load a QML document to c++.

  QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

    // Create root object for the UI
    AbstractPane *root = qml->createRootObject<AbstractPane>();


    app->setScene(root);
}

How do I access the objects of the QMLdocument, such as a button etc; from C++. I need to access them to find the memory address of a specific object in the QML document.


回答1:


ImageView* iv= root->findChild<bb::cascades::ImageView*>("myImageView");

and in QML

 ImageView 
 {
      // ...
      objectName: "myImageView"
 }

Edit: Don't forget to clean and rebuild the project.



来源:https://stackoverflow.com/questions/19952754/accessing-qml-objects-from-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!