[Solved] Accessing QML children with QObject::findChild
Visual Studio 2010, qt5.2.1
I have for includes:
In QML, i have a bTrying to access a child of a QML root object in C++, I have the following setup code:
@ QQuickView *ui;
ui = new QQuickView;
root = ui->rootObject();
grid = Root->findChild("theGrid", Qt::FindDirectChildrenOnly);
Visual studio has a mouseover error on the indirection operator on line 13 of the example: "Error: no instance of function template "QObject::findChild" matches the argument list." What am I doing wrong?
findChild is a template function so you have to give the type of the child you are searching.
In your case:
@ grid = Root->findChild<QObject *>("theGrid", Qt::FindDirectChildrenOnly);@
Thanks, this was indeed the problem!