class MyData { public: void setData(int value) { m_value = value; } int data() const { return m_value; } private: int m_value = 0; }; QScriptValue myValue = engine.newObject(); MyData* dataObject = new MyData(); dataObject->setData(42); myValue.setData(QScriptValue::PointerBeingStored, dataObject);
QLabel* label = new QLabel("Hello, world!"); QScriptValue myValue = engine.newQObject(label); myValue.setData(QScriptValue::PointerBeingStored, label);In this example, a new QLabel object is created and associated with a QScriptValue object using the newQObject function. The QLabel object is also stored in the QScriptValue object using the setData function. This allows the JavaScript program to access the QLabel object and call its functions. The package library for QScriptValue and setData is part of the QtScript library, which is included with the Qt framework.