Recive Signal inside QML Object
-
I am little bit confused how to receive a signal, I have a signal called onvalueChanged, and according to it I will append data inside my plot! any Advice how to handle it?
ChartView { id:chartView1 onvalueChanged: lineseries1.append(i, value) } -
I am little bit confused how to receive a signal, I have a signal called onvalueChanged, and according to it I will append data inside my plot! any Advice how to handle it?
ChartView { id:chartView1 onvalueChanged: lineseries1.append(i, value) }that depends on where the signal actually comes from, can you explain a but more?
- is it a c++ class somewhere
- a signal declared inside an other QML-file
- is it part of the ChartView itself?
- ....
In any case, in QML you can access usually signals that are bound to properties by the following Syntax;
on + propertyName + Changed
in your case, most likelyonValueChanged, but this may or may not be sufficient, you'll have to say where the signal comes from -
that depends on where the signal actually comes from, can you explain a but more?
- is it a c++ class somewhere
- a signal declared inside an other QML-file
- is it part of the ChartView itself?
- ....
In any case, in QML you can access usually signals that are bound to properties by the following Syntax;
on + propertyName + Changed
in your case, most likelyonValueChanged, but this may or may not be sufficient, you'll have to say where the signal comes fromThanks @J.Hilk for your clarification, it is from C++, Q_PROPERTY
like this on; http://doc.qt.io/qt-5/qtqml-cppintegration-exposecppattributes.htmlQ_PROPERTY(QString value READ value WRITE setValue NOTIFY valueChanged) -
Thanks @J.Hilk for your clarification, it is from C++, Q_PROPERTY
like this on; http://doc.qt.io/qt-5/qtqml-cppintegration-exposecppattributes.htmlQ_PROPERTY(QString value READ value WRITE setValue NOTIFY valueChanged)@MAthias_Va
alight,
that means, the signal you're actually listening to is indeedonValueChanged: //do something
attention to the capital
Vfollowup question, how do you instantiate the c++ class?
If it's registered as a qml component, you'll have to add the line inside that body.
If it's a context property you'll have to useConnect -
at the moment I can receive the signal inside my QML file, but My problem is, I canto integrate it as I need!!
for example If I create a timer inside my ChartView I can receive the signal as below example; which is working as expected
ChartView { id:chartView1 Timer { id:timer interval: 200 ; running: true; repeat: true; onTriggered: onvalueChanged: lineseries1.append(i, value) //here I don't receive error } }but I don't want to use this Timer, I need to receive the signal as my beginning example! Any Ideas?
ChartView { id:chartView1 onvalueChanged: lineseries1.append(i, value) //here I have error: Cannot assign to non-existent property } -
at the moment I can receive the signal inside my QML file, but My problem is, I canto integrate it as I need!!
for example If I create a timer inside my ChartView I can receive the signal as below example; which is working as expected
ChartView { id:chartView1 Timer { id:timer interval: 200 ; running: true; repeat: true; onTriggered: onvalueChanged: lineseries1.append(i, value) //here I don't receive error } }but I don't want to use this Timer, I need to receive the signal as my beginning example! Any Ideas?
ChartView { id:chartView1 onvalueChanged: lineseries1.append(i, value) //here I have error: Cannot assign to non-existent property }@MAthias_Va
I'm puzzled the timer works at all!!?!?again, how to you access the c++ class?
did you use
- qmlRegisterType<yourClass>
- or setContextProperty
- or something else
?
-
@MAthias_Va
I'm puzzled the timer works at all!!?!?again, how to you access the c++ class?
did you use
- qmlRegisterType<yourClass>
- or setContextProperty
- or something else
?
@J.Hilk I use: setContextProperty
-
@J.Hilk I use: setContextProperty
@MAthias_Va said in Recive Signal inside QML Object:
@J.Hilk I use: setContextProperty
alight, assuming the following :
rootContext()->setContextProperty("myClass", myClassInstance);
than you can do the following
ChartView { id:chartView1 Connections{ target: myClass onValueChanged: console.log("c++ value changed to:", value); } } -
@MAthias_Va said in Recive Signal inside QML Object:
@J.Hilk I use: setContextProperty
alight, assuming the following :
rootContext()->setContextProperty("myClass", myClassInstance);
than you can do the following
ChartView { id:chartView1 Connections{ target: myClass onValueChanged: console.log("c++ value changed to:", value); } }Thanks @J.Hilk so much, this one is working :) :)