Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Dialog QtQuick access problem
Forum Updated to NodeBB v4.3 + New Features

Dialog QtQuick access problem

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 663 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tycos
    wrote on last edited by
    #1

    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&#40;&#41;;
    

    }
    @

    main.qml
    @
    import QtQuick 2.2
    import QtQuick.Window 2.0
    import QtQuick.Dialogs 1.2
    import QtQuick.Controls 1.2

    Window {
    id: mainWindow
    objectName: "mainWindow"
    visible: true
    width: 640
    height: 480

    Item {
        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?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved