Javascript to qml (integration issue)
-
I have a javascript script that works fine but I need it to work fine within Qt.
Original 'working' JS script:
@
var pusher = new Pusher("cb65d0a7a72cd94adf1f");
var channel = pusher.subscribe("ticker.155");
channel.bind("message", function(data) {
//console.log(data);
var topbuy = data.trade.topbuy;
var topsell = data.trade.topsell;
console.log("Buy Price: ", topbuy.price,
"Buy Quantity:", topbuy.quantity),
console.log("Sell Price: ", topsell.price,
"Sell Quantity:", topsell.quantity);
});
@But when I try and implement the code into QML, I start getting errors as though QML does not understand the code (constructor/event)
Error:
Starting C:\Qt\Qt5.3.1\5.3\mingw482_32\bin\qmlscene.exe...
file:///C:/Qt5/Tools/QtCreator/bin/projects/echoQML/pusherScript.js:2: ReferenceError: Pusher is not definedechoQML.qml:
@
import QtQuick 2.2
import "pusherScript.js" as PusherscriptConnections{
signal send (string notice)
}
@pusherScript.js:
@
Qt.include("pusher.min.js")
var pusher = new Pusher("cb65d0a7a72cd94adf1f"); //this is the line it chokes on
var channel = pusher.subscribe("ticker.155");
channel.bind("message", function(data) {
//console.log(data);
var topbuy = data.trade.topbuy;
var topsell = data.trade.topsell;
console.log("Buy Price: ", topbuy.price,
"Buy Quantity:", topbuy.quantity),
console.log("Sell Price: ", topsell.price,
"Sell Quantity:", topsell.quantity);
});
@How do I properly integrate this script into Qt?
[edit: added missing coding tags @ SGait]
-
You import "pusherScript.js", but use Qt.include for call "pusher.min.js"?
-
I am following the documentation http://qt-project.org/doc/qt-5/qtqml-javascript-imports.html
-
Maybe an error in "type".
-
Not sure. The Javascript portion should be error free. It executes on it's own just fine.
Why QML Javascript interpreter cannot intemperate it, I have not a clue. -
I referer to "documentaion"... maybe an error in “type” (in documentation).
I will read docs and tried...
Good luck!
-
Thank you kindly for your response.
I am neck deep in the doc and very confused by this error. I am newish to c++ web programming. I know c++ and qt ok and I know www a lot. But not the 2 mixed. :(