相关疑难解决方法(0)

如何从C++访问嵌套的QML对象?

这是一个可重复的例子:

main.qml


import QtQuick 2.0

Item {
    id : root
    width: 360
    height: 360

    Text {
        id : t1
        text: qsTr("Hello World")
        property int someNumber: 1000
        anchors.centerIn: parent
    }
    MouseArea {
        anchors.fill: parent
        onClicked: {
            Qt.quit();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

main.cpp中


#include <QtGui/QGuiApplication>
#include <QQmlEngine>
#include <QQmlComponent>
#include <QQmlProperty>
#include <QDebug>

#include "qtquick2applicationviewer.h"

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QtQuick2ApplicationViewer viewer;
    viewer.setMainQmlFile(QStringLiteral("qml/untitled/main.qml"));
    viewer.showExpanded();

    QQmlEngine engine;
    QQmlComponent component(&engine, "qml/untitled/main.qml");
    QObject *object = component.create();

    qDebug() << "Property value:" << QQmlProperty::read(object, …
Run Code Online (Sandbox Code Playgroud)

c++ qt qml qtquick2 qtcore

14
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++ ×1

qml ×1

qt ×1

qtcore ×1

qtquick2 ×1