Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

newable script objects: QScriptEngine vs. QQMLEngine/QJSEngine

$
0
0
I was able to figure out something that might work. As a work around I declared a function as Q_INVOKABLE in the object that the script context inherits from. In that object I create a javascript compatible object and return it. A simple new myobject() also works but I don’t think it confers ownership to the script and it will never be deleted. QJSValue contextclass::myobject( int Row, int Column ) {    Application* app = dynamic_cast< Application* >( QCoreApplication::instance() );    if ( !app )       throw ::std::runtime_error( "Could not obtain application object" );    // this confers ownership to javascript but not sure when garbage collection will happen    return app->view->engine()->newQObject( new myobject() ); } I also tried the following. It compiled but I never could get the script to invoke it:    // create a script wrapped proxy object as a QScriptValue    cellReferenceFactory = view->engine()->newQObject( &_myobject );    // Create a script wrapped QJSValue that will instantiate a new object    cellReferenceInstance = cellReferenceFactory.callAsConstructor();    // tell the engine to create a property that will instantiate a myobject object    view->engine()->globalObject().setProperty( "myobject", cellReferenceInstance ); I tried to create it using “Qt.myobject” and “Qt.myobject()” ( view is the QQuickView for the application)

Viewing all articles
Browse latest Browse all 4972

Latest Images

Trending Articles



Latest Images