Dialog QtQuick access problem
-
Hi to everybody,
I've a little problem with the access to Dialog Qt Quick object from c++ side. When I try access to a Dialog object in qml I have some problem if it's not in a "Rectangle" or "Item" object.
main.cpp
@
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QDebug>
#include <QObject>int main(int argc, char *argv[])
{
QApplication app(argc, argv);QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:///main.qml"))); // Step 1: get access to the root object QObject *rootObject = engine.rootObjects().first(); qDebug() << rootObject->objectName(); QObject *qmlObj = rootObject->findChild<QObject*>("testItem"); qDebug() << qmlObj->objectName(); QObject *qmlDialog = qmlObj->findChild<QObject*>("testObj"); qDebug() << qmlDialog->objectName(); // this doesn't works qmlDialog = rootObject->findChild<QObject*>("testObj2"); qDebug() << qmlDialog->objectName(); // this doesn't works qmlDialog = rootObject->findChild<QObject*>("testObj3"); qDebug() << qmlDialog->objectName(); return app.exec();
}
@main.qml
@
import QtQuick 2.2
import QtQuick.Window 2.0
import QtQuick.Dialogs 1.2
import QtQuick.Controls 1.2Window {
id: mainWindow
objectName: "mainWindow"
visible: true
width: 640
height: 480Item { id: testItem objectName: "testItem" Dialog { id: testObj objectName: "testObj" modality: Qt.WindowModal contentItem: Rectangle { Text { text: "Test Obj" } } } } MessageDialog { id: testObj2 objectName: "testObj2" text: "Test Obj" } Dialog { id: testObj3 objectName: "testObj3" modality: Qt.WindowModal contentItem: Rectangle { Text { text: "Test Obj" } } }
}
@
In particular it doesn't works when I try to access at testObj2 and testObj3. Why?