2011-08-17 17 views
5

Sto cercando di ottenere QML per interagire con FB graph API utilizzando FB Javascript SDK.Esiste un modo in cui QML può caricare i dati utilizzando Facebook Javascript SDK?

sto caricando questo HTML all'interno di un elemento WebView:

html: "<script>console.log(\"This is in WebKit!\"); window.FB.init();</script>" 

e ho anche creato un oggetto finestra JS chiamato FB all'interno del WebView:

javaScriptWindowObjects: QtObject { 
      WebView.windowObjectName: "FB" 
     } 

Ma non appena la window.FB.init() viene chiamato, si getta fuori un errore:

ReferenceError: Can't find variable: window 

un altro approccio che sto utilizzando è caricare il FB .init function() utilizzando 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(); 

ma ho l'errore come:

TypeError: Result of expression 'FB.init' [undefined] is not a function 

Ecco 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(); 
    } 

} 

risposta

0

Credo che il problema è che si non stanno definendo nulla nel tuo oggetto-finestra, il tuo QtObject contiene solo il windowObjectName ma non funziona o vars. windowObjectName è in realtà solo il nome del nuovo oggetto, qml non usa l'importazione-"fb.js" per quell'oggetto.

Secondo il docs si suppone di simile a questa:

WebView { 
    javaScriptWindowObjects: QtObject { 
    WebView.windowObjectName: "FB" 

    // the stuff you want in that window-object goes here: 
    function init() { 
     console.log("FB.init"); 
    } 
    } 
}