[Interest] QQmlApplicationEngine's rootObject() returns 0 objects count when trying to import of JavaScript file from Remote Server

ashish dabhade ashishd157 at gmail.com
Thu Nov 13 08:27:19 CET 2014


Hi All,

I'm trying to import a JavaScript file from a Remote Server in QML file as

import QtQuick 2.3
import QtQuick.Window 2.2
import "http://192.168.0.16/sample.js" as Remote

Window {
    visible: true
    width: 360
    height: 360

    MouseArea {
        anchors.fill: parent
        onClicked: {
            console.log(Remote.myFunction())
        }
    }

    Text {
        objectName: "myText"
        text: qsTr("Hello World")
        anchors.centerIn: parent
    }
}

sample.js:

function myFunction() {
    var d = new Date();
    var n = d.toString();
    return n;
}

and main.cpp:

QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
qDebug() << engine.rootObjects().count();

So the problem here is engine.rootObjects().count() prints 0 in the above
scenario but the import succeeds as Remote.myFunction() properly prints the
date.

Now keeping everything the same and just commenting the import line
properly shows objects count as 1.
Also importing the javascript file locally also succeeds.
Is this a known issue ?

Environment:
Kubuntu 14.04, Qt 5.3.2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20141113/c5eaec03/attachment.html>


More information about the Interest mailing list