[QT 4.8] QTBride system, connect C++ signal with parameter -> Javascript slot
-
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 ! -
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.
-
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.
-