I'm trying to make a change to a property of a (Rectangle) object that was instantiated in QML, but I'm not able to do it because the findChild strong null .
I'm following the following documentation:
- Integrating QML and C ++
I'm trying to make a change to a property of a (Rectangle) object that was instantiated in QML, but I'm not able to do it because the findChild strong null .
I'm following the following documentation:
- Integrating QML and C ++
I found a solution, but I could not understand why the findChild method returns null . When I performed some tests, I realized that the rootObjects method returned an object that had the same objectname as the object that has the object that I want to change the property and thus returns the window I was able to perform the property change and search for other objects.
Basically the source stayed this way.
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQuickView>
#include <QQuickItem>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
QObject *rect = engine.rootObjects().first()->findChild<QObject *>("rect");//Alerado de rootContext para rootObjects
if (rect)
rect->setProperty("color", "blue");
return app.exec();
}
Intheapp