c++ - cascades and signals / slots -
c++ - cascades and signals / slots -
i'm running around in circles this. can't wrap head around signals , slots.
just looking mechanism can automatically update ui when signal in c++ occurs.
example:
i have 2 labels in qml have text: _app.method returns value.
i have button onclicked runs q_invokable method. method emits signal when it's done, eg, fetches geocordinates , updates values above text: assignments rely on.
what want update text: assignments 1 time values change.
i need these signals / slots explained plainly. examples in documentation seem assume qml or c++ not mix of both. sample code have examples, not explained in documentation.
if had plain description, im sure adapt it. eg, 1: define in qml, 2: define in hpp file, 3: define these in cpp file.
i've tried using qobject's setpropery("text","value") app crashes when attempting this.
tell me if i'm wrong...
1) in qml:
button { id: abutton text: _app.value onclicked: { _app.valuechanged.connect(abutton.onvaluechanged); _app.value = _app.value + 1; } function onvaluechanged (val) { abutton.text = "new value: " + val; } }
2) in hpp:
q_property(int value read value write setvalue notify valuechanged) public: int value(); void setvalue(int i); signals: void valuechanged(int); private: int m_ivalue;
3) in cpp:
int class::value() { homecoming m_ivalue; } void class::setvalue(int i) { // name same hpp write q_property statement m_ivalue = i; emit valuechanged(m_ivalue); }
so, happens that, in qml, onclick method connects signal qml function; means, we're listening value change, , when does, function called. then, alter value... since q_property set write value function called setvalue, setvalue called new value; internally, m_ivalue changed, , emit occurs, tells whoever listening valuechanged there's new value.
hey, qml listening that! (via _app.valuechanged.connect script). so, qml object (the button) listening that, has it's onvaluechanged function called, new value (because of emit valuechanged(m_ivalue).
please tell me i've figured out??!?!
if using q_property macro, there's no need bind onvaluechanged signal function explicitly alter button's text. , need not emit valuechanged signal m_ivalue. create below mentioned changes in corresponding files
qml:
button { horizontalalignment: horizontalalignment.center verticalalignment: verticalalignment.center id: abutton text: _app.value onclicked: { _app.value = _app.value + 1 } }
hpp:
signals: void valuechanged();
cpp:
emit valuechanged();
c++ signals qml blackberry-cascades slots
Comments
Post a Comment