Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. [QT 4.8] QTBride system, connect C++ signal with parameter -> Javascript slot

[QT 4.8] QTBride system, connect C++ signal with parameter -> Javascript slot

Scheduled Pinned Locked Moved Qt WebKit
4 Posts 2 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Magnas
    wrote on last edited by
    #1

    Hi Everyone,

    I'm working with Qt 4.8 and I have some troubles with the Bridge system.
    I read the QtBridge documentation and I easily can connect my simple signal with a javascript function, but i still can't succeed to link my C++ signal with parameters with my javascript function.

    For exemple, I have my Object myObject which is link to my javascript code and has a signal @void tagada(QString message);@
    How can i send the "message" parameter emited by the signal to my javascript function ? I tried many things like
    @
    function monSlot(p)
    {
    alert(p);
    }
    alert("ok");
    myObject.tagada.connect(monSlot(d));
    @
    or
    @
    function monSlot(p)
    {
    alert(p);
    }
    alert("ok");
    myObject.tagada(d).connect(monSlot(d));
    @
    but it wasn't effective at all...
    thanks in advance !

    1 Reply Last reply
    0
    • McLionM Offline
      McLionM Offline
      McLion
      wrote on last edited by
      #2

      You need three things:

      This is the function registered to and called from JavaScript for bridge functionality:
      @
      void QT_MainWindow::webGUIbuttonClick(QByteArray LinkID)
      {
      //your code
      }

      @

      Adding this (QT_MainWindow) object to the WebFrame for bridge functionality

      @void QT_MainWindow::populateJavaScriptWindowObject()
      {
      ui->web->page()->mainFrame()->addToJavaScriptWindowObject("NativeBridge", this);
      }
      @

      And preparing adding objects to JavaScript (bridge from JS to native code)
      @connect(ui->web->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(populateJavaScriptWindowObject()));@

      Now use this in your js:
      @NativeBridge.webGUIbuttonClick(linkID)@

      Works here with this simple code.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Magnas
        wrote on last edited by
        #3

        Thanks for your reply,

        I already have done the 2 firsts things, but what I want to do is to send a QString with my C++ signal to my function written in JS.

        I have seen this in the documentation:
        @ function myInterestingScriptFunction() { ... }
        ...
        myQObject.somethingChanged.connect(myInterestingScriptFunction);@

        and it works when the signal "somethingChanged" send nothing (like this exemple) , but not when this signal send a QString or whatever else...

        if somewhere inside a function of myObject I do :
        @emit tagada("success")
        @

        I wanna have a JS function which take this string and do some stuff with it.

        1 Reply Last reply
        0
        • McLionM Offline
          McLionM Offline
          McLion
          wrote on last edited by
          #4

          I haven't tried in this direction since I am only needing to bring over arguments from JS to C++, which works in my case.

          So, if it basically works to call a function in JS in your case, there might be something wrong with the arguments definition.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved