Estoy tratando de hacer que QML interactúe con la API de gráficos FB usando FB Javascript SDK.¿Hay alguna forma de que QML pueda cargar datos mediante Facebook Javascript SDK?
estoy cargando este código HTML dentro de un elemento WebView:
html: "<script>console.log(\"This is in WebKit!\"); window.FB.init();</script>"
y también he creado un objeto ventana llamado JS FB dentro de la vista Web:
javaScriptWindowObjects: QtObject {
WebView.windowObjectName: "FB"
}
Pero tan pronto como el window.FB.init() se llama, que arroja un error:
ReferenceError: Can't find variable: window
Otro enfoque que estoy usando es cargar el FB .init función() usando 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();
pero me sale el error como:
TypeError: Result of expression 'FB.init' [undefined] is not a function
Aquí es la completa QML:
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();
}
}