从C ++访问QML对象 [英] Accessing QML objects from C++

查看:128
本文介绍了从C ++访问QML对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是编写的代码,用于将QML文档加载到c ++.

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);
}

如何访问QML文档的对象,例如按钮等;来自C ++.我需要访问它们以在QML文档中找到特定对象的内存地址.

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.

推荐答案

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

和QML

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

别忘了清理并重建项目.

Don't forget to clean and rebuild the project.

这篇关于从C ++访问QML对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆