Hello ,

I am facing some confusion regarding passing data between the qt qick slider and QQuickItem object in C++, that results in application crash. I have the following class with the defined properties:

Qt Code:
  1. class TessellationSceneItem : public QQuickItem
  2. {
  3. Q_OBJECT
  4. //the property defintion must be at the top of the class
  5. //the notify signal is needed for correct property bindings
  6. Q_PROPERTY(float outer READ outer WRITE setOuter NOTIFY outerChanged)
  7. Q_PROPERTY(float inner READ inner WRITE setInner NOTIFY innerChanged)
  8. Q_PROPERTY(float maxPatchVertices READ maxPatchVertices NOTIFY maxPatchVerticesChanged)
  9.  
  10. public:
  11. TessellationSceneItem();
  12.  
  13. void setOuter(float);
  14. void setInner(float);
  15.  
  16. float inner();
  17. float outer();
  18.  
  19. float maxPatchVertices() const;
  20.  
  21. signals:
  22. void innerChanged();
  23. void outerChanged();
  24. void maxPatchVerticesChanged();
  25. .............
  26. ............
  27. private:
  28.  
  29. TeapotTessellation* mTessScene;
  30.  
  31. QTime mTIme;
  32.  
  33. };
To copy to clipboard, switch view to plain text mode 

The definition of the setter and getter methods:

Qt Code:
  1. void TessellationSceneItem::setOuter(float outerFactor)
  2. {
  3. if(outerFactor == mTessScene->outerTessellationFactor())
  4. return;
  5.  
  6. mTessScene->setOuterTessellationFactor(outerFactor);
  7. //do not emit notifier if value does not actually change
  8. emit outerChanged();
  9. }
  10.  
  11. void TessellationSceneItem::setInner(float innerFactor)
  12. {
  13. if(innerFactor == mTessScene->innerTessellationFactor())
  14. return;
  15.  
  16. mTessScene->setInnerTessellationFactor(innerFactor);
  17. emit innerChanged();
  18. }
  19.  
  20. float TessellationSceneItem::inner()
  21. {
  22. return (float)(mTessScene->innerTessellationFactor());
  23. }
  24.  
  25. float TessellationSceneItem::outer()
  26. {
  27. return (float)(mTessScene->outerTessellationFactor());
  28. }
  29.  
  30. float TessellationSceneItem::maxPatchVertices() const
  31. {
  32. return (float) (mTessScene->getMaxPatchVertices());
  33. }
To copy to clipboard, switch view to plain text mode 

The idea is to have the slider value loaded with the value set in the underlying C++ application. Then with every slider interaction , the underlying value( outer, inner) in the C++ side will be updated. I tried the following in the .qml file , but the application crashes.

Qt Code:
  1. import QtQuick 2.0
  2. import QtQuick.Controls 1.1
  3. import QtQuick.Layouts 1.1
  4. import TeapotTessellation 1.0
  5.  
  6. Item {
  7. id: root
  8. width: 512; height: 512
  9.  
  10.  
  11. TessellationSceneItem
  12. {
  13. id: tessSceneItem
  14. // outer: outerTessellationSlider.value
  15. // inner: innerTessellationSlider.value
  16. }
  17.  
  18. GridLayout {
  19. id: controlLayout
  20. columns: 2
  21.  
  22. Text {
  23. id: outerTessellationText
  24. text: qsTr("Outer Tess. Factor: ")
  25. color: "black"
  26. opacity: 1.0
  27. }
  28.  
  29. Slider {
  30. id: outerTessellationSlider
  31. opacity: 1.0
  32. // value: tessSceneItem.outer
  33. minimumValue: 1.0
  34. maximumValue: 64//tessSceneItem.maxPatchVertices
  35. stepSize: 1.0
  36. Layout.fillWidth: true
  37. }
  38.  
  39.  
  40. Text {
  41. id: innerTessellationText
  42. text: qsTr("Inner Tess. Factor: ")
  43. color: "black"
  44. opacity: 1.0
  45. }
  46.  
  47.  
  48.  
  49. Slider {
  50. id: innerTessellationSlider
  51. opacity: 1.0
  52. // value: tessSceneItem.inner
  53. minimumValue: 1.0
  54. maximumValue: 64.0//tessSceneItem.maxPatchVertices
  55. stepSize: 1.0
  56. Layout.fillWidth: true
  57. }
  58. }
  59.  
  60.  
  61. Rectangle {
  62. id: rect
  63. color: "red"
  64. radius: 10
  65. opacity: 0.1
  66. border.color: "black"
  67. anchors.fill: controlLayout
  68. }
  69. }
To copy to clipboard, switch view to plain text mode 

The commented part of the .qml file are the places that cause the application crash. Any hint ?

Thanks