Hello,
I’m trying to figure out in which context dynamically generated items are being stored?
Therefor let me explain my scenario.
First I’ve registered two new QML types:
qmlRegisterType<MyViewController>("uicontrollers", 1, 0, "ViewController");
qmlRegisterType<MyTabController>("uicontrollers", 1, 0, "TabController");
Then I used them in qml files:
mainview.qml
Rectangle {
Component
{
id: tab_factory
MyTab {}
}
TabView
{
id: a_tabview
//some code here ...
}
ViewController
{
id: view_controller
objectName: "myViewController"
onNewTab:
{
var tab_obj = tab_factory.createObject(a_tabview)
var a_tab = a_tabview.addTab(a_name, tab_obj)
a_tab.active = true
}
}
MyTab.qml
Component
{
id: the_tab
Rectangle {
id: tab_frame
border.width: 0
property string the_name: ""
SplitView
{
id: a_tab_split
// some items here ...
}
TabController
{
id: my_tab_controller
objectName: "myTabController"
Component.onCompleted:
{
console.log(my_tab_controller)
}
}
}
}
Dynamic tab creation works fine from my C++ class.
Therefor I use the function described below to find my ViewController and emit newTab signal.
But when I try to find the created TabController in the QML context I get no results:
uicontroller.h
//*****************************************************************************
//** Template FindMyQMLObjects
//*****************************************************************************
template<typename T> QList<T> FindQMLObjects(QString in_name)
{
QList<T> ret;
QList<QObject*> root_obj_list = m_engine.rootObjects();
foreach(QObject* obj, root_obj_list)
{
qDebug() << "root_obj name: " << obj->objectName();
ret = obj->findChildren<T>(in_name, Qt::FindChildrenRecursively);
if (ret.size() > 0) break;
}
return ret;
}
Any idea where my QML objects are hiding?
Thanks for your help.
Best regards,
Rainer
↧








