J'essaie de faire interagir QML avec l'API graphique FB en utilisant FB Javascript SDK.
Je charge ce HTML dans un élément WebView :
html: "<script>console.log(\"This is in WebKit!\"); window.FB.init();</script>"
et j'ai également créé un objet JS Window Object nommé FB à l'intérieur du WebView :
javaScriptWindowObjects: QtObject {
WebView.windowObjectName: "FB"
}
Mais dès que la fonction window.FB.init() est appelée, une erreur se produit :
ReferenceError: Can't find variable: window
Une autre approche que j'utilise est de charger la fonction FB.init() en utilisant Component.onComplete
function startupFunction() {
console.log("This call is in QML!");
FB.init({
appId:'XXXXXXXXXXXXX', cookie:true,
status:true
});
console.log(FB);
}
Component.onCompleted: startupFunction();
Mais j'obtiens l'erreur suivante :
TypeError: Result of expression 'FB.init' [undefined] is not a function
Voici le QML complet :
import QtQuick 1.0
import "fb.js" as FB
import QtWebKit 1.0
Rectangle {
width: 360
height: 360
Text {
text: "Hello World"
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
}
WebView {
preferredWidth: 490
preferredHeight: 400
scale: 0.5
smooth: false
javaScriptWindowObjects: QtObject {
WebView.windowObjectName: "FB"
}
html: "<script>console.log(\"This is in WebKit!\"); window.FB.init();</script>"
function startupFunction() {
console.log("This call is in QML!");
FB.init({
appId:'xxxxxxxxxxxx', cookie:true,
status:true
});
console.log(FB);
}
Component.onCompleted: startupFunction();
}
}