ClickableRectangle.qml

Qt Code:
  1. import QtQuick 2.0;
  2.  
  3. Rectangle
  4. {
  5. width: 40; height: 40; x: 0; y: 0;
  6.  
  7. // Fluorescent green
  8. color:'#23FF23';
  9.  
  10. border.color: 'black'; border.width: 2; radius: 100
  11.  
  12. property int key;
  13. signal iHaveBeenCalled (var key);
  14.  
  15. MouseArea
  16. {
  17. anchors.fill: parent;
  18. onClicked:
  19. {
  20. iHaveBeenCalled.call (0, key)
  21. }
  22. }
  23. }
To copy to clipboard, switch view to plain text mode 



GUIControllers.js


Qt Code:
  1. .import "GlobalVariablesAndFunctions.js" as GlobalVariablesAndFunctions
  2.  
  3. function createDynamicRectangles ()
  4. {
  5. /// Returns a Component object created using the QML file at the specified url, or null if an empty
  6. /// string was given.
  7. var component = Qt.createComponent ("ClickableRectangle.qml");
  8. /// The returned component's Component::status property indicates whether the component was
  9. /// successfully created.
  10. if (component.status === Component.Ready)
  11. {
  12. /// arrayOfXAxixOfPoints and arrayOfYAxixOfPoints are the arrays holding x and y axis coordinates
  13. /// of the rectangles (respectively) to be plotted.
  14. /// Both these arrays are techincally supposed to have equal number of points which will the
  15. /// determine number of rectangles to be plotted.
  16. for (var i = 0; i < GlobalVariablesAndFunctions.arrayOfXAxixOfPoints.length; i++)
  17. {
  18. dynamicRectangles[i] = component.createObject (vehicleDrivingAreaRect, {x: 0, y: 0})
  19.  
  20. /// After an object of the component is created at a specified default position (0, 0) in our
  21. /// case, we can calculate and reset its position and other properties at leisure as follows.
  22. dynamicRectangles[i].x = GlobalVariablesAndFunctions.arrayOfXAxixOfPoints[i] - (dynamicRectangles[i].width / 2)
  23. dynamicRectangles[i].y = GlobalVariablesAndFunctions.arrayOfYAxixOfPoints[i] - (dynamicRectangles[i].height / 2)
  24. }
  25.  
  26. numberOfDynamicRectanglesActive = GlobalVariablesAndFunctions.arrayOfXAxixOfPoints.length
  27. }
  28. }
To copy to clipboard, switch view to plain text mode 

main.qml

Qt Code:
  1. import QtQuick 2.0
  2. import "GUIControllers.js" as GUIControllers
  3.  
  4. Rectangle
  5. {
  6. id: rootContainer
  7. width: 360
  8. height: 360
  9. Text {
  10. text: qsTr("Hello World")
  11. anchors.centerIn: parent
  12. }
  13. MouseArea {
  14. anchors.fill: parent
  15. onClicked: {
  16. GUIControllers.createDynamicRectangles()
  17. }
  18. }
  19. }
To copy to clipboard, switch view to plain text mode 

The error in the title appears in GUIControllers.js at this line:
Qt Code:
  1. if (component.status === Component.Ready)
To copy to clipboard, switch view to plain text mode