I have a two dimensional float array in QML. How do I get its values in C++.

I have created a class in c++ and have done the part of qmlRegisterType. The class is now accessible in QML.

Please demonstrate with a small example.

This is what I have tried:

Qt Code:
  1. #ifndef TEST_H
  2. #define TEST_H
  3.  
  4. #include <QObject>
  5. #include <QQuickItem>
  6. #include <iostream>
  7.  
  8. class Test: public QObject
  9. {
  10. private:
  11. Q_OBJECT
  12.  
  13. Q_PROPERTY(QVariantList name READ name WRITE setName)
  14. QVariantList m_name;
  15.  
  16. public:
  17. QVariantList name() const
  18. {
  19. return m_name;
  20. }
  21.  
  22. public slots:
  23. void setName (QVariantList arg)
  24. {
  25. m_name = arg;
  26.  
  27. QVector<QVariant> p = m_name.toVector ();
  28. std::cout << p.first ().toInt ();
  29. }
  30. };
  31.  
  32. #endif // TEST_H
To copy to clipboard, switch view to plain text mode 

The c++ part is giving me a segmentation fault.

QML:
Qt Code:
  1. import QtQuick 2.2
  2. import QtQuick.Window 2.1
  3.  
  4. import AGVUI 1.0
  5.  
  6. Window {
  7. visible: true
  8. width: 360
  9. height: 360
  10.  
  11. function createTwoDimensionalArray (twoDimArray, rows, cols)
  12. {
  13. /// Creates all lines.
  14. for (var i = 0; i < rows; i++)
  15. {
  16. /// Creates an empty line.
  17. twoDimArray.push ([]);
  18.  
  19. /// Ads colunms to the empty line.
  20. twoDimArray [i].push (new Array (cols));
  21.  
  22. for (var j = 0; j < cols; j++)
  23. {
  24. /// Default initialization to zero
  25. twoDimArray [i][j] = 0
  26. }
  27. }
  28.  
  29. return twoDimArray
  30. }
  31.  
  32. Test
  33. {
  34. Component.onCompleted:
  35. {
  36. var arr = []
  37. createTwoDimensionalArray (arr, 2, 2)
  38.  
  39. setName(arr)
  40. }
  41. }
  42.  
  43. MouseArea {
  44. anchors.fill: parent
  45. onClicked: {
  46. Qt.quit();
  47. }
  48. }
  49.  
  50. Text {
  51. text: qsTr("Hello World")
  52. anchors.centerIn: parent
  53. }
  54. }
To copy to clipboard, switch view to plain text mode