sajis997
31st December 2014, 08:29
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:
class TessellationSceneItem : public QQuickItem
{
Q_OBJECT
//the property defintion must be at the top of the class
//the notify signal is needed for correct property bindings
Q_PROPERTY(float outer READ outer WRITE setOuter NOTIFY outerChanged)
Q_PROPERTY(float inner READ inner WRITE setInner NOTIFY innerChanged)
Q_PROPERTY(float maxPatchVertices READ maxPatchVertices NOTIFY maxPatchVerticesChanged)
public:
TessellationSceneItem();
void setOuter(float);
void setInner(float);
float inner();
float outer();
float maxPatchVertices() const;
signals:
void innerChanged();
void outerChanged();
void maxPatchVerticesChanged();
.............
............
private:
TeapotTessellation* mTessScene;
QTime mTIme;
};
The definition of the setter and getter methods:
void TessellationSceneItem::setOuter(float outerFactor)
{
if(outerFactor == mTessScene->outerTessellationFactor())
return;
mTessScene->setOuterTessellationFactor(outerFactor);
//do not emit notifier if value does not actually change
emit outerChanged();
}
void TessellationSceneItem::setInner(float innerFactor)
{
if(innerFactor == mTessScene->innerTessellationFactor())
return;
mTessScene->setInnerTessellationFactor(innerFactor);
emit innerChanged();
}
float TessellationSceneItem::inner()
{
return (float)(mTessScene->innerTessellationFactor());
}
float TessellationSceneItem::outer()
{
return (float)(mTessScene->outerTessellationFactor());
}
float TessellationSceneItem::maxPatchVertices() const
{
return (float) (mTessScene->getMaxPatchVertices());
}
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.
import QtQuick 2.0
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
import TeapotTessellation 1.0
Item {
id: root
width: 512; height: 512
TessellationSceneItem
{
id: tessSceneItem
// outer: outerTessellationSlider.value
// inner: innerTessellationSlider.value
}
GridLayout {
id: controlLayout
columns: 2
Text {
id: outerTessellationText
text: qsTr("Outer Tess. Factor: ")
color: "black"
opacity: 1.0
}
Slider {
id: outerTessellationSlider
opacity: 1.0
// value: tessSceneItem.outer
minimumValue: 1.0
maximumValue: 64//tessSceneItem.maxPatchVertices
stepSize: 1.0
Layout.fillWidth: true
}
Text {
id: innerTessellationText
text: qsTr("Inner Tess. Factor: ")
color: "black"
opacity: 1.0
}
Slider {
id: innerTessellationSlider
opacity: 1.0
// value: tessSceneItem.inner
minimumValue: 1.0
maximumValue: 64.0//tessSceneItem.maxPatchVertices
stepSize: 1.0
Layout.fillWidth: true
}
}
Rectangle {
id: rect
color: "red"
radius: 10
opacity: 0.1
border.color: "black"
anchors.fill: controlLayout
}
}
The commented part of the .qml file are the places that cause the application crash. Any hint ?
Thanks
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:
class TessellationSceneItem : public QQuickItem
{
Q_OBJECT
//the property defintion must be at the top of the class
//the notify signal is needed for correct property bindings
Q_PROPERTY(float outer READ outer WRITE setOuter NOTIFY outerChanged)
Q_PROPERTY(float inner READ inner WRITE setInner NOTIFY innerChanged)
Q_PROPERTY(float maxPatchVertices READ maxPatchVertices NOTIFY maxPatchVerticesChanged)
public:
TessellationSceneItem();
void setOuter(float);
void setInner(float);
float inner();
float outer();
float maxPatchVertices() const;
signals:
void innerChanged();
void outerChanged();
void maxPatchVerticesChanged();
.............
............
private:
TeapotTessellation* mTessScene;
QTime mTIme;
};
The definition of the setter and getter methods:
void TessellationSceneItem::setOuter(float outerFactor)
{
if(outerFactor == mTessScene->outerTessellationFactor())
return;
mTessScene->setOuterTessellationFactor(outerFactor);
//do not emit notifier if value does not actually change
emit outerChanged();
}
void TessellationSceneItem::setInner(float innerFactor)
{
if(innerFactor == mTessScene->innerTessellationFactor())
return;
mTessScene->setInnerTessellationFactor(innerFactor);
emit innerChanged();
}
float TessellationSceneItem::inner()
{
return (float)(mTessScene->innerTessellationFactor());
}
float TessellationSceneItem::outer()
{
return (float)(mTessScene->outerTessellationFactor());
}
float TessellationSceneItem::maxPatchVertices() const
{
return (float) (mTessScene->getMaxPatchVertices());
}
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.
import QtQuick 2.0
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
import TeapotTessellation 1.0
Item {
id: root
width: 512; height: 512
TessellationSceneItem
{
id: tessSceneItem
// outer: outerTessellationSlider.value
// inner: innerTessellationSlider.value
}
GridLayout {
id: controlLayout
columns: 2
Text {
id: outerTessellationText
text: qsTr("Outer Tess. Factor: ")
color: "black"
opacity: 1.0
}
Slider {
id: outerTessellationSlider
opacity: 1.0
// value: tessSceneItem.outer
minimumValue: 1.0
maximumValue: 64//tessSceneItem.maxPatchVertices
stepSize: 1.0
Layout.fillWidth: true
}
Text {
id: innerTessellationText
text: qsTr("Inner Tess. Factor: ")
color: "black"
opacity: 1.0
}
Slider {
id: innerTessellationSlider
opacity: 1.0
// value: tessSceneItem.inner
minimumValue: 1.0
maximumValue: 64.0//tessSceneItem.maxPatchVertices
stepSize: 1.0
Layout.fillWidth: true
}
}
Rectangle {
id: rect
color: "red"
radius: 10
opacity: 0.1
border.color: "black"
anchors.fill: controlLayout
}
}
The commented part of the .qml file are the places that cause the application crash. Any hint ?
Thanks