2016-05-31 2 views
0

JS 함수에서 내 메인 페이지에 "Block_Cloud.qml"요소를 표시하려고합니다. 다음 문서에도 불구하고 결과가 없습니다. Official docthis exampleJS에서 QML 객체 만들기

다른 프로젝트에서 이미 내 JS 함수를 사용하고 있습니다.

import QtQuick 2.0 
import QtQuick.Controls 1.3 

Rectangle { 
    id:block 
    property alias textBlock: textBlock.text 
    property alias descriptionCloud: descriptionCloud.text 
    property alias checkBoxName : cloudCheckBox.text 
    property alias theBoxIsChecked : cloudCheckBox.checked 
    width: 100 
    height: 62 
    color:"red" 

Text{ 

    id:textBlock 
    text:"Nuage n°" 
    CheckBox { 
     id: cloudCheckBox 
     x: 25 
     y: 29 
     text: "test" 
     anchors.left:textBlock.left 
     anchors.top:textBlock.bottom 
    } 
    Text{ 
     id:descriptionCloud 
     text:"test" 
     anchors.top:cloudCheckBox.bottom 
    } 

} 
} 

내 DataConfigBuilder.js :

내 Block_Cloud.qml입니다

.import QtQuick 2.0 as QtQuickModuleImportedInJS 

//CLASSES 
function Cloud(name, description){ 
    this.name = name; 
    this.description = description; 
    this.getName = function(){ 
     return this.name; 
    } 
    this.getDescription = function(){ 
     return this.description; 
    } 
} 

//DATA 
var configCloudList = []; 

//Functions REGISTER 
function configCloudRegister(cloudList){ 
    var length = cloudList.length; 
    for(var i=0; i<length;i++){ 
     var cloud = new Cloud(cloudList[i].name,cloudList[i].description); 
     configCloudList.push(cloud); 
    } 

} 

//Functions SHOW 
function showTheClouds(parentBox){ 
    for(var i=0; i<configCloudList.length; i++){ 
     var component = Qt.createComponent("Block_Cloud.qml"); 

     if(component.status == QtQuickModuleImportedInJS.Component.Ready){ 
      var dynamicObject = component.createObject(parentBox); 
      if(dynamicObject == null){ 
       console.log("error creatng block"); 
       console.log(component.errorString()); 
       return false; 
      } 
      var lastChild = parentBox.children.length; 
      dynamicObject.parent = parentBox; 
      dynamicObject.y = lastChild*62; 
      dynamicObject.textBlock = "Cloud n°"+ i; 
      dynamicObject.checkBoxName = configCloudList[i].name; 
      dynamicObject.descriptionCloud=configCloudList[i].description; 

    }else{ 
     console.log("error loading block component"); 
     console.log(component.errorString()); 
     return false; 
    } 
} 
    return false; 
} 

그리고 내 main.qml : 당신의 도움 :)

에 대한

import QtQuick 2.4 
import QtQuick.Controls 1.3 
import QtQuick.Window 2.2 
import QtQuick.Dialogs 1.2 
import "DataConfigBuilder.js" as DataConfigBuilder 



ApplicationWindow { 
    title: qsTr("Hello World") 
    width: 400 
    height: 400 
    visible: true 

    function myQmlFunction(configCloudList){ 
     DataConfigBuilder.configCloudRegister(configCloudList) 
     DataConfigBuilder.showTheClouds(newDisplayCloud) 
     return "CloudList for config recieved" 
    } 

    Rectangle{ 
     id:newDisplayCloud 
     color:"pink" 
     width: 384 
     height: 302 
    } 



} 

감사

답변

0

내 오류를 발견했습니다. 나는 수정할 수 없습니다. 함수 QML에서 함수 "showTheClouds"는 아무 것도하지 않습니다. 신호를 통해 구성 요소에서이를 호출해야합니다.