I` ve got such component as QMLDoubleEdit
import QtQuick 1.1
Item{
property double dVal: 0;
Rectangle {
TextInput {
id: textDVal
focus:true
validator:DoubleValidator{
bottom:0;
top:200;
decimals: 3
}
text: dVal
}
}
}
When it used to implement UI in for example
Item{
property double dWesMax: 0;
property double dWesMin: 0;
Rectangle {
QMLDoubleEdit {
id: edtMaxWes
x: 40
y: 50
dVal: dWesMax
}
QMLDoubleEdit {
id: edtMinWes
x: 260
y: 50
dVal: dWesMin
}
}
}
I can set it initial values from my *.cpp code, but i can`t read them after changing:
// that is ok
QDeclarativeContext *context=m_qmlFrmParam->rootContext();
context->setContextProperty("dWesMax",m_wntModule->getWesMax());
// that is not
double dVal=0;
dVal=(m_dlgRoot->property("dWesMax")).toDouble();
Better explain here: 1) Creating UI
void frmWesParam::prepareElements(){
m_qmlFrmParam=new QDeclarativeView();
m_qmlFrmParam->setSource(QUrl("qrc:/view/wesparams/QMLBgPanel.qml"));
m_qmlFrmParam->setResizeMode(QDeclarativeView::SizeRootObjectToView);
m_dlgRoot=m_qmlFrmParam->rootObject();
QDeclarativeContext *context=m_qmlFrmParam->rootContext();
context->setContextProperty("viewerWidget",this);
}
void frmWesParam::setWesMax(double dVal){
m_dlgRoot->setProperty("dWesMax",QString::number(dVal));
}
2) Showing it (just row of elements QMLDoubleEdit, and two buttons - "Ok","Cancel" onPress, emiting accept or cancel)
frmWesParam *vw=new frmWesParam();
vw->setWesMax(14.3);
vw->show();
3) When widget appears, it contain my value - 14.3. Here user can change it, and push button; 4) On signal accept i got
void frmWesParam::catchAccept(){
if(m_wntModule!=0){
double dVal=0;
dVal=(m_dlgRoot->property("dWesMax")).toDouble();
qDebug()<<dVal;
}
And here i got only what i sat setWesMax(...) .