Details
-
Bug
-
Resolution: Duplicate
-
P3: Somewhat important
-
None
-
5.2.0 Beta1
-
None
Description
Carrying on from QTBUG-35386, I'm trying to get the same thing to work with QJSEngine, since it's unlikely to be fixed in QScriptEngine.
#include <QtCore> #include <QtQml> class Object : public QObject { Q_OBJECT public: Q_PROPERTY(int x READ x WRITE setX) Object(int x) : mX(x) {} int x() const { return mX; } void setX(int x) { mX = x; } private: int mX; }; class Context : public QObject { Q_OBJECT public: Q_PROPERTY(QSharedPointer<Object> object READ object) Context(QSharedPointer<Object> object) : mObject(object) {} QSharedPointer<Object> object() const { return mObject; } private: QSharedPointer<Object> mObject; }; int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); Q_UNUSED(a); QJSEngine engine; QSharedPointer<Object> objectPtr(new Object(5)); Context context(objectPtr); engine.globalObject().setProperty("context", engine.newQObject(&context)); qDebug() << engine.evaluate("context.object.x").toString(); return 0; } #include "main.moc"
Output:
"undefined"
Attachments
Issue Links
- duplicates
-
QTBUG-43080 QML should handle QSharedPointer<QObjectDerived> types
- Reported
- replaces
-
QTBUG-40045 Need smart pointers as properties
- Closed