Details
-
Suggestion
-
Resolution: Unresolved
-
P2: Important
-
None
Description
In the attached project, MyType.qml is processed by qmltc.
Code
// Main.qml import QtQuick import QmltcStudy Window { width: 800 height: 600 visible: true MyType { id: qmlObj objectName: "qmlObj" } Component.onCompleted: console.log("Created from QML:", qmlObj) }
// main.cpp #include <QGuiApplication> #include <QQmlApplicationEngine> #include "mytype.h" int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.loadFromModule("QmltcStudy", "Main"); QmltcStudy::MyType cppObj(&engine); qDebug() << "Created from C++:" << &cppObj; auto qmlObj = engine.rootObjects().first()->findChild<QObject*>("qmlObj"); qDebug() << "Attempting to cast QML to C++:" << qobject_cast<QmltcStudy::MyType*>(qmlObj); return app.exec(); }
Debug output
qml: Created from QML: MyType_QMLTYPE_1(0x2ca59d22340, "qmlObj") Created from C++: QmltcStudy::MyType(0xe67e3ff968) Attempting to cast QML to C++: QObject(0x0)
Analysis
There are 2 different types with 2 different QMetaObjects.
I was under the impression that the QML engine would instantiate the qmltc-generated C++ class instead of using MyType.qml, but it looks like this isn't the case. I'm not sure if this is a bug or unimplemented functionality.
Attachments
Issue Links
- is required for
-
QTBUG-105538 qmltc evolution collection task
-
- Open
-