Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9134481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:40:05+00:00 2026-06-17T08:40:05+00:00

In qt4 qml the qtwebkit 1.0 the component webview has a property javaScriptWindowObjects .

  • 0

In qt4 qml the qtwebkit 1.0 the component webview has a property javaScriptWindowObjects. I used it to add javaScriptWindowObjects to the context of my webpages javascript to call c++ functions. like so

WebView{
    url: "http://test.com"
    anchors.fill: parent
    scale: 1.0

    javaScriptWindowObjects: QtObject {
        WebView.windowObjectName: "native"

        function foo(x, y) {
             console.log("This is a call from javascript");
             myCppHandler.fooNative(b,c);
         }
    }
}

so i can call it from the webpages javascript like so

<script type="text/javascript">
    native.foo(1,2)
</script>

but in qt5 qml qtwebkit 3.0 there is no such thing like javaScriptWindowObjects

how can i achieve that in qt5 qml?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:40:07+00:00Added an answer on June 17, 2026 at 8:40 am

    Just for the record to get this done:

    import QtQuick 2.0
    import QtWebKit 3.0
    import QtWebKit.experimental 1.0
    
    Rectangle {
    
       width: 1024
       height: 768
    
       WebView{
           url: "http://localhost"
           anchors.fill: parent
    
           experimental.preferences.navigatorQtObjectEnabled: true
           experimental.onMessageReceived: {
    
               console.debug("get msg from javascript")
               experimental.postMessage("HELLO")
           }
       } // webview
    } // rectanlge
    
    
    <html>
    <body>
    <h1>It just works!</h1>
    
    <p>Play with me...</p>
    
    <button onclick="nativecall();">test</button>
    <div id="out"></div>
    
    <script type="text/javascript">
        function nativecall(){
            console.log("will try native call");
            var elem = document.getElementById("out").innerHTML="clicked";
            navigator.qt.postMessage('this is a js call');
        }
    
        function jsCall(message){
            var elem = document.getElementById("out").innerHTML="and the other way around " + message;
        }
    
        navigator.qt.onmessage = function(ev) {
            jsCall(ev.data);
        }
    </script>
    
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Qt4 has support for Drag & Drop actions and I've used them like in
I am slowly getting used to using the Qt4 GUI framework. In a project
In Qt4 I used to use QT += multimedia phonon //... #include <Phonon> //...
I'm studying the Qt4 library and I want to add some functionality to all
I have a C++ project that is using QT4. I've used QT Designer to
I'm having trouble defining a custom property in a QML item: Item { property
We have a PyQt4/PySide Qt4 video player app that has QToolButton object in the
Language: C++ Toolkit: Qt4 The toolkit I'm using has a static method called int
I'm using Qt4.8 on OSX Leopard and instead of qmake + QtCreator I want
Create a simple Qt4 Gui Application, surround the window construction and show commands in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.