Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a pointer to some qml element from QDeclarativeView?

Tags:

c++

qt

qml

We had some QDeclarativeView, we loaded and opened qml file. How to get pointer to some of its elements (say QWebView from qml's WebView with some Id, placed inside some rectangle)?

like image 713
myWallJSON Avatar asked Sep 06 '25 03:09

myWallJSON


1 Answers

I think you need to read this

It explains how to get a reference to a qml object in the section named "Loading QML components from C++"

QML components are essentially object trees with children that have siblings and their own children. Child objects of QML components can be located using the QObject::objectName property with QObject::findChild(). For example, if the root item in MyItem.qml had a child Rectangle item:

So if you need to get a reference you have to write something like

QObject *object = yourview.rootObject();
QObject *your_obj = object->findChild<QObject*>("yourobjName");
like image 58
nax83 Avatar answered Sep 07 '25 22:09

nax83