create a qml object using javascript

155
3
Jump to solution
01-11-2021 03:38 AM
rsharma
Occasional Contributor III

hi

i want to create qml object of the below code. can anyone help

NetworkRequest {
    id: networkRequest
    url: "http://appstudio.arcgis.com/images/index/introview.jpg"
    responsePath: fileFolder.path +"/appstudio.jpg"

    property url imagePath: responsePath

   onReadyStateChanged: {
        console.log("Ready state"+readyState);
        if (readyState == NetworkRequest.DONE) {
        image.source = internal.folderUrl+"/appstudio.jpg";
       }
    }
   //onProgressChanged: console.log("progress:", progress)
    onError: {
        console.log(errorText + ", " + errorCode)
        //On failure, don't use the local copy
        image.source = ""
    }
}
Reply
0 Kudos
1 Solution

Accepted Solutions
SeanKim
New Contributor III

Just for your reference.

var newObj = Qt.createQmlObject("import QtQuick 2.12;import ArcGIS.AppFramework 1.0; NetworkRequest{id:networkRequest}", root, "");
newObj.onReadyStateChanged.connect(function f(){
    console.log("Ready state:" + newObj.readyState)
    if (newObj.readyState === NetworkRequest.DONE){
        console.log("done")
    }
})
newObj.url = "http://appstudio.arcgis.com/images/index/introview.jpg"
newObj.send();

 

View solution in original post

Reply
0 Kudos
3 Replies
ErwinSoekianto
Esri Regular Contributor

@rsharma 

 

Did you mean creating QML objects dynamically? Take a look at this, https://doc.qt.io/qt-5/qtqml-javascript-dynamicobjectcreation.html 

 

Erwin

Reply
0 Kudos
SeanKim
New Contributor III

Just for your reference.

var newObj = Qt.createQmlObject("import QtQuick 2.12;import ArcGIS.AppFramework 1.0; NetworkRequest{id:networkRequest}", root, "");
newObj.onReadyStateChanged.connect(function f(){
    console.log("Ready state:" + newObj.readyState)
    if (newObj.readyState === NetworkRequest.DONE){
        console.log("done")
    }
})
newObj.url = "http://appstudio.arcgis.com/images/index/introview.jpg"
newObj.send();

 

View solution in original post

Reply
0 Kudos
rsharma
Occasional Contributor III

hi @SeanKim 

when i check for newtworkrequest done, it always give me the error

 

 

 if (newObj.readyState === NetworkRequest.DONE){
        console.log("done")
    }

 

 

 

ReferenceError: NetworkRequest is not defined

so i tried like this way

 

 

if(newObj.readyState===4){
            console.log("done");
            DB.insertMediaDetails(dev_href_fname,ref_no,ref_type);
            console.log("done inserting");
            return dev_href_fname;
        }

 

 

calling fnc DB.insertMediaDetails(dev_href_fname,ref_no,ref_type); 

 but it always return  fron this cond before readystate become 4 and return undefined 

Reply
0 Kudos