Advertisement
chinmaya_n

Untitled

Jun 19th, 2012
1,036
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*********************************************************
  2. Text.qml
  3. **********************************************************/
  4. import QtQuick 1.1
  5.  
  6. Rectangle {
  7.     width: parent.width
  8.     height: parent.height
  9.     color: "transparent"
  10.  
  11.     Text {
  12.         font.family: "Gabriola"
  13.         font.pointSize: 15
  14.         color: "white"
  15.         text: "This is static text"
  16.     }
  17.  
  18.     MouseArea {
  19.         anchors.fill: parent
  20.         onClicked: {
  21.             Qt.quit()
  22.         }
  23.     }
  24. }
  25.  
  26. /*********************************************************
  27. MainView.qml
  28. **********************************************************/
  29.  
  30. import QtQuick 1.1
  31. import "./Try_js.js" as GO
  32.  
  33. Rectangle {
  34.     id: mainView
  35.     width: 240
  36.     height: 320
  37.     color:"black"
  38.  
  39.     Component.onCompleted: GO.createSpriteObjects("mainView","Text.qml","{}")
  40. }
  41.  
  42. /*********************************************************
  43. Try_js.js
  44. **********************************************************/
  45. var component;
  46. var sprite;
  47.  
  48. function createSpriteObjects(parent,thing,props) {
  49.     console.log(parent+":"+thing+":"+props);
  50.     component = Qt.createComponent(thing);
  51.     console.log("created component!");
  52.     if (component.status == Component.Ready) {
  53.         console.log("Component is Ready: "+component);
  54.         finishCreation(parent,props);
  55.     }
  56.     else
  57.         component.statusChanged.connect(finishCreation(parent,props));
  58. //    console.log("created component!");
  59. }
  60.  
  61. function finishCreation(parent,props) {
  62.     console.log(parent+":"+props);
  63.     if (component.status == Component.Ready) {
  64.         sprite = component.createObject(parent, props);
  65.         if (sprite == null) {
  66.            // Error Handling
  67.             console.log("Error creating object");
  68.         }
  69.     }
  70.     else if (component.status == Component.Error) {
  71.        // Error Handling
  72.         console.log("Error loading component:", component.errorString());
  73.     }
  74. }
  75.  
  76. /**************************************
  77. Compiled output
  78. ****************************************/
  79. Qml debugging is enabled. Only use this in a safe environment!
  80. mainView:Text.qml:{}
  81. created component!
  82. Component is Ready: QDeclarativeComponent(0xa361a0)
  83. mainView:{}
  84. <Unknown File>: QML Component: createObject: value is not an object
  85. Error creating object
  86. C:\QtSDK\Desktop\Qt\4.8.0\mingw\bin\qmlviewer.exe exited with code 0
Advertisement
RAW Paste Data Copied
Advertisement