Nominate our 2022 Qt Champions!

QML and strophe.js

  • I'm experimenting using Strophe.js to get BOSH connection between my server and QML app (mostly because it would make HTML5<->QML porting reeeally easy in case of certain kind of apps that use BOSH). I have nothing else but a qml with import strophe.js as Strophe and there I try to var connection = new Strophe.Connection(myBoshServer) as told in strophe tutorial.

    Result is: TypeError: Result of expression 'Strophe.Connection' [undefined] is not a constructor.

    I have absolutely no idea why / what that means. Same stuff works perfectly as a HTML5 app.

    Any ideas? Thanks!

    Additional info from strophe.js:

    @/** Constructor: Strophe.Connection

    • Create and initialize a Strophe.Connection object.
    • Parameters:
    • (String) service - The BOSH service URL.
    • Returns:
    • A new Strophe.Connection object.
      Strophe.Connection = function (service)

    edit: and here's the whole thing of beauty:

    @import QtQuick 1.1
    import "./strophe.js" as Strophe

    Rectangle {
    width: 640
    height: 360
    MouseArea {
    anchors.fill: parent
    onClicked: {
    var connection = new Strophe.Connection("");

  • Try changing:

    @var connection = new Strophe.Connection("");@


    @var connection = new Strophe.Strophe.Connection("");@

    When you import a js file all the variables and functions are given the namespace under the as ....


    import "myjs.js" as myjs


    Read this for more info:

  • Thanks kbcool, that was the problem there of course! However it seems that the Strophe.js would require fair amount of tweaking to get it working with the QML so I gave up and search other way to do it.

    Thanks anyway!

Log in to reply