Details
-
Suggestion
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
Description
Code
// TestObject.qml
import QtQuick QtObject { property int qmlNnumber: 42 }
// Main.qml
import QtQuick Window { width: 640 height: 480 visible: true TestObject { objectName: "qmlObject" } }
// main.cpp
#include <QGuiApplication> #include <QQmlApplicationEngine> #include "testobject.h" static void reportProperties(QObject* testObj) { qDebug() << "#####"; qDebug() << testObj; qDebug() << "#####"; auto metaObj = testObj->metaObject(); for (int i = 0; i < metaObj->propertyCount(); ++i) { QMetaProperty prop = metaObj->property(i); qDebug() << "PROPERTY" << prop.name(); qDebug() << "\tValue:" << prop.read(testObj); qDebug() << "\tBindable:" << prop.isBindable(); qDebug() << "\thasNotifySignal:" << prop.hasNotifySignal(); } } int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; QObject::connect( &engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.loadFromModule("PropertyStudy", "Main"); reportProperties( engine.rootObjects().first()->findChild<QObject*>("qmlObject") ); reportProperties( new PropertyStudy::TestObject(&engine)); return app.exec(); }
Output
##### TestObject_QMLTYPE_1(0x1b9bf750dd0, name = "qmlObject") ##### PROPERTY objectName Value: QVariant(QString, "qmlObject") Bindable: true hasNotifySignal: true PROPERTY qmlNnumber Value: QVariant(int, 42) Bindable: false hasNotifySignal: true ##### PropertyStudy::TestObject(0x1b9bf728b80) ##### PROPERTY objectName Value: QVariant(QString, "") Bindable: true hasNotifySignal: true PROPERTY qmlNnumber Value: QVariant(int, 42) Bindable: true hasNotifySignal: false
- The two objects are of different types
- For the QML-instantiated object, "qmlNumber" is not bindable and has a notify signal
- For the C++-instantiated object, "qmlNumber" is bindable and has no notify signal