Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Exposing third-party API to QtScript



  • Hello, Im working in a proyect where some plugin capabilities are need, because I need this plugins to be multiplataform, then I desired to try out making this with QtScript.
    One of the API's I want to expose is OpenSceneGraph, then my plugins developers, can render advanced 3D scenes without worry about plataform issues.
    But I stuck because can't figure out how to convert from a OSG type to a QtScriptValue and viceversa.
    For example, I want to expose "osgDB::readNodeFile()":http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs/a01557.html#177e1656d3766fcab9e38c7681fb94b3, It's form is:

    @osg::Node* osgDB::readNodeFile(const std::string &filename;, const ReaderWriter::Options *options)@

    Then create the wrapper funcion as show in:

    http://doc.qt.nokia.com/latest/qscriptengine.html#newFunction

    @// Create the wrapper funtion.
    static QScriptValue osgDB_readNodeFile(QScriptContext *context, QScriptEngine *engine)
    {
    // Obtains the arguments from QtScript.
    QScriptValue filename = context->argument(0):
    QScriptValue options = context->argument(1):

    // Here is my first question, ¿How I can convert from QScriptValue to a OSG type?
    osg::Node *retval = osgDB::readNodeFile(filename.toString().constData(), optionsretval.toOSG());
    
    //And second, ¿How I can convert from a OSG type to QScriptValue?
    return toQtScript(retval);
    

    }@

    Of course, a second (and more easy) option is to distribute the plugins as source code, and making it binary by compiling at install time, but I think the first option is more correct.
    Some clue about this problem will be appreciated.


Log in to reply