3

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.

DesirePRG
  • 6,122
  • 15
  • 69
  • 114

1 Answers1

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

and in QML

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

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

Mercurial
  • 2,095
  • 4
  • 19
  • 33
  • but when i do std::cout << &(*iv) << std::endl; it always returns 0 – DesirePRG Nov 13 '13 at 12:04
  • That means there is no object in your QML with that name. Check if you are loading the appropriate QML file and if it loads successfully, and check the objectName once again. Also, try cleaning the project. findChild goes through the tree of components and searches for the component with the objectName that equals the argument passed. – Mercurial Nov 13 '13 at 12:25
  • Yes you are correct. I had to clean and build the file, and now it works. Thanks alot for the guidance – DesirePRG Nov 13 '13 at 13:28