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

Best way to expose a QObject to JavaScript without QWebFrame?



  • Hey there,

    I am interested in exposing a QObject in my program to JavaScript and I am wondering how to expose it.
    I saw the following code example on the QtWebKit Bridge doc page:
    @
    // ...
    QWebFrame *frame = myWebPage->mainFrame();
    frame->addToJavaScriptWindowObject("someNameForMyObject", myObject);
    // ...
    @

    The problem with exposing the QObject this way is that it appears to require you to have a QWebView, something I'm not really eager to do in the part of my application I'm dealing with. Is there a way to expose my QObject to JavaScript without being constricted by having a QWebView in my application?

    Thanks!



  • What exactly do you want to achieve?

    We have in one of our applications a JavaScript interface which uses QScriptEngine and the meta object system of Qt to access the objects. I am not sure if that is what you want to have.



  • I would like to open up part of my application to a website I am building



  • If your really dont want to use the WebFrame you might use json objects and read it again if a request comes in.



  • how exactly would that work? Is it possible to have the web frame without having the web view?


Log in to reply