Below is the given code snippet of the qml file which is loaded through a cpp file of a qt project. In this i want to directly call a .js file fucntion createGrid to run on PowerCell elements in a loop which are commented to create a grid.

This gives the error: Invalid import for import line of .js file

Qt Code:
  1. import Qt 4.7
  2. import "loop.js" as genList
  3.  
  4. Rectangle {
  5. id:page
  6. width: 550; height:159
  7. x:0
  8. y:0
  9. signal gridEntry
  10. property variant listOfPowerHogs: powerHogList
  11. Image {
  12. id: backGround
  13. source: "ui_images/background.png"
  14.  
  15. Flickable{
  16. id:flick
  17. anchors.fill: parent
  18. contentWidth: flickArea.width
  19. contentHeight: flickArea.height
  20. flickableDirection: Flickable.HorizontalFlick
  21. Grid{
  22. id:flickArea
  23. x:0
  24. y:12
  25. width: 697
  26. height: 135
  27. rows: 1; columns: 5; spacing: 8;
  28. // PowerCell {
  29. // width:/* page.inPortrait ? (parent.width-4)/2 : (parent.width-8)/3*/ (parent.width-100)/4
  30. // iconValue: listOfPowerHogs[0]
  31. // instrumentedStatus: listOfPowerHogs[1]
  32. // }
  33. // PowerCell {
  34. // width: (parent.width-100)/4
  35. // iconValue: listOfPowerHogs[2]
  36. // instrumentedStatus: listOfPowerHogs[3]
  37. // }
  38. // PowerCell {
  39. // width: (parent.width-100)/4
  40. // iconValue: listOfPowerHogs[4]
  41. // instrumentedStatus: listOfPowerHogs[5]
  42. // }
  43. // PowerCell {
  44. // width: (parent.width-100)/4
  45. // iconValue: listOfPowerHogs[6]
  46. // instrumentedStatus: listOfPowerHogs[7]
  47. // }
  48.  
  49. genList.createGrid(listOfPowerHogs)
  50.  
  51. }
  52. states: State {
  53. name: "ShowBars"
  54. when: view.movingVertically || view.movingHorizontally
  55.  
  56. }
  57. transitions: Transition {
  58. NumberAnimation { properties: "opacity"; duration: 400 }
  59. }
  60. }
  61. ScrollBar {
  62. id: horizontalScrollBar
  63. width: flick.width-12; height: 12
  64. anchors.bottom: flick.bottom
  65. opacity: 0
  66. orientation: Qt.Horizontal
  67. position: flick.visibleArea.xPosition
  68. pageSize: flick.visibleArea.widthRatio
  69. }
  70. }
  71. }
To copy to clipboard, switch view to plain text mode