01-10-2013 01:48 AM
Hi, I want to create item dynamically.
Before I want to create it using qml, but seems not possible
So maybe better use C++ to create it dynamically,
I'm already try it but still fail
So I have a custom control qml (a Navigation Pane)
the structure is like this :
How to add action item to that .qml ?
I'm already try this, but fail
QObject *object = component.create();
Page *myPage = object->findChild<Page*>("myPage"); // maybe on this I'm wrong implement it ?? -> not found?
ActionItem* action1 = ActionItem::create().title("First action");
How to create this Action Item dynamically?
Solved! Go to Solution.
01-10-2013 05:04 AM
in QML, the object name must be between " " marks.
So your Page's object name will be:
You can reach any QML object from cpp like this:
//this snippet is from YourProjectName.cpp
// create scene document from main.qml asset // set parent to created document to ensure it exists for the whole // application lifetime QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(th
is); // create root object for the UI AbstractPane *root = qml->createRootObject<AbstractPane>(); // set created root object as a scene app->setScene(root); //and here comes the findChild method Page* qmlPage = root->findChild<Page*>("myPage");
After this, You can create any QML object from C++ side, like your own code:
ActionItem* action1 = ActionItem::create().title("First action"); myPage->addAction(action1, ActionBarPlacement:nBar);
Don't need to create a QObejct, or declarative stuff.
01-10-2013 06:29 AM
Hi I try your suggestion, and it works
I forgot to add * *marks on object name
And I'm wrong on this:
I use VideosPage.qml on createqmlDocument
QmlDocument *qml = QmlDocument::create("asset:///VideosPage.qml").par
actually using main.qml will work no need use that custom.qml, as long custom.qml use at main.qml I think
Thanks for your reply